import time
import math
b = 0
print(' ')
print('Hello, welcome to our bakery!')
print('What would you like to buy?')
print(' ')
time.sleep(1)
print('Cake')
time.sleep(1)
print('Biscuit')
time.sleep(1)
print('Ice Cream')
time.sleep(1)
a = str(input(' '))
if(a == 'Cake'):
b = int(input('How many? (1 Slice of Cake is 1.99$)'))
elif (a == 'Biscuit'):
c = input('How many? (1 Biscuit is 0.99$)')
elif (a == 'Ice Cream'):
d = input('How many? (One Ice Cream ball is 1.99$)')
else:
print('You ordered wrong! Make sure you type it correct.')
run
result_b = b * 1.99
float(print(result_b))
#π Previous Error
44 messages Β· Page 1 of 1 (latest)
Hey @silver oyster!
It looks like you pasted Python code without syntax highlighting.
Please use syntax highlighting to improve the legibility of your code and make it easier for us to help you.
To do this, use the following method:
```py
print('Hello, world!')
```
This will result in the following:
print('Hello, world!')```
You can **edit your original message** to correct your code block.
@silver oyster
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Closes after a period of inactivity, or when you send !close.
what should I do to avoid this error
float(print(result_b)): Why are you passing the return of print to float?
Do you understand what print is for?
@silver oyster
Yes
Why are you calling float on that line? Passing the return of print to float is the problem, but it's not clear why you're using float there at all now that I read the code again.
a = str(input(' '))
input returns a string casting a string to a string is useless
Sorry, calling out print was actually a red herring.
to make it be able to print float numbers too
idk im not that good in python π
result_b is already a float though.
!e
result_b = 1.99
print(result_b)
@alpine ruin :white_check_mark: Your 3.12 eval job has completed with return code 0.
1.99
print() has no return value, or the return value "None", but you cannot cast None to a float, so the error is thrown
I tried
if(a == 'Cake'):
b = int(input('How many? (1 Slice of Cake is 1.99$)'))
result_b = b * 1.99
float(print(result_b))
when you type a number
multiply it with 1.99
and print
Yes, but result_b is already a float.
you are still trying to cast None into a float, that is not possible
Calling float there doesn't make sense.
okay
print returns None
what should I do
remove the cast
Remove the call to float.
π
oh
Yes, like I showed above.
You're welcome. I'd encourage you to understand exactly why you got the error that you did though, if you don't fully understand it yet.
Understanding how return values and arguments work is very important, as is thinking about the purpose of function calls.
where can I learn them better?
i recommend programming books. but you can also use you tube tutorials, but they are usually not very complete and usually do not explain how and why it works
Just practice. Practice using functions. Eventually, their use will become more familiar.
Also, think about error messages when you get them. That error message you got told you everything you needed to know to solve this.
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.