Python Forum
problem with data type
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
problem with data type
#1
Hi guys,
I am struggling on resolving a question which says:

bookstore() takes 2 string arguments: book & price
bookstore returns a string in sentence form
bookstore() should call title_it_rtn() with book parameter
gather input for book_entry and price_entry to use in calling bookstore()
print the return value of bookstore()

here is my code:

def bookstore(book, price):
price = float(price)
title_it_rtn = (book, price)
return title_it_rtn

title_it_rtn = (input("entry_book: ")), (float(input(“entry_price: “)))
print(“Title:”,“book”, “,costs”,”$”,float(price))
How do I change price into float from string?
result shows that the price is not defined but if I gave it double quotes it wont work.

Thanks for help
Reply
#2
How about printing it out like
print("Title:" + book + " costs $ " + str(price))
Second of all, I don't exactly understand your code. You make a function, but you aren't even calling it anywhere?
So instead, how about you first define the function with all the necessary commands in it, and then call It ?
pyzyx3qwerty
"The greatest glory in living lies not in never falling, but in rising every time we fall." - Nelson Mandela
Need help on the forum? Visit help @ python forum
For learning more and more about python, visit Python docs
Reply
#3
(Apr-14-2020, 11:22 AM)pyzyx3qwerty Wrote: How about printing it out like
print("Title:" + book + " costs $ " + str(price))
Second of all, I don't exactly understand your code. You make a function, but you aren't even calling it anywhere?
So instead, how about you first define the function with all the necessary commands in it, and then call It ?

Thanks for the suggestion, however, I've tried to deal with the questions then I found that I dont actually need def part to execute whole code but that makes me fail to follow the questions. I've highlighted the part which can work independently.

My new code:
def bookstore(book, price):
    title_it_rtn = (book, price)
    return title_it_rtn

[b]book = input("book_entry: ")
price = input("price_entry: ")
print("Title,",book,",cost$",price)[/b]
Reply
#4
Yes, this indeed is working fine. But(just asking) why do you have the function in the code when you don't use it? I have tried running it, and it works all the same without the function.
pyzyx3qwerty
"The greatest glory in living lies not in never falling, but in rising every time we fall." - Nelson Mandela
Need help on the forum? Visit help @ python forum
For learning more and more about python, visit Python docs
Reply
#5
(Apr-15-2020, 11:08 AM)pyzyx3qwerty Wrote: Yes, this indeed is working fine. But(just asking) why do you have the function in the code when you don't use it? I have tried running it, and it works all the same without the function.

Well..I simply followed the instructions which tells me how to code it. I believe I have some difficulty on my logic, haven't I?
So I could really use ur help on this plz.
Thanks for replies.

bookstore() takes 2 string arguments: book & price
bookstore returns a string in sentence form
bookstore() should call title_it_rtn() with book parameter
gather input for book_entry and price_entry to use in calling bookstore()
print the return value of bookstore()
Reply
#6
I do undestand what is needed by two first steps but third gets me lost so I just skip it

  1. bookstore() takes 2 string arguments: book & price
  2. bookstore returns a string in sentence form
  3. bookstore() should call title_it_rtn() with book parameter
  4. gather input for book_entry and price_entry to use in calling bookstore()
  5. print the return value of bookstore()

#1 - bookstore takes two arguments:

def bookstore(book, price):
#2 - return value should be string in sentence form

def bookstore(book, price):
    return f'Title "{book}" costs ${price}'
#4 get book_entry and price_entry from user
#5 print sentence using data from user:

# lets assume that:
# book_entry is 'Algorithms + Data Structures = Programs'
# book_price is 19.84

>>> print(bookstore(book_entry, price_entry))                                                                     
Title "Algorithms + Data Structures = Programs" costs $19.84
Algorithms + Data Structures = Programs by Niklaus Wirth at amazon
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#7
So the 3rd item - title_it_rtn() should be another function. Is it possible that the "book" argument in item 1 is supposed to be a ISBN number or something that then you use that function to look up the title?

Otherwise that 3rd question is an enigma.
Reply
#8
Thank you guys I've managed to deal with it by all the suggestions from you.
Thanks a lot

def bookstore(book, price):
    title_it_rtn = (book.capitalize(), price)
    return title_it_rtn

title_it_rtn = (input("book_entry: "), input("price_entry: "))
print("Title,",book,",cost$",price)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  container data type formatting nzcan 5 3,807 Aug-10-2018, 05:45 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020