#πŸ”’ Previous Error

44 messages Β· Page 1 of 1 (latest)

silver oyster
#
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))
royal stirrupBOT
#

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.
royal stirrupBOT
#

@silver oyster

Python help channel opened

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.

silver oyster
#

what should I do to avoid this error

alpine ruin
#

float(print(result_b)): Why are you passing the return of print to float?

#

Do you understand what print is for?

#

@silver oyster

silver oyster
#

the way I use

alpine ruin
#

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.

cerulean charm
#
a = str(input(' '))

input returns a string casting a string to a string is useless

alpine ruin
#

Sorry, calling out print was actually a red herring.

silver oyster
#

idk im not that good in python 😭

alpine ruin
#

!e

result_b = 1.99
print(result_b)
royal stirrupBOT
#

@alpine ruin :white_check_mark: Your 3.12 eval job has completed with return code 0.

1.99
cerulean charm
#

print() has no return value, or the return value "None", but you cannot cast None to a float, so the error is thrown

silver oyster
#

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

alpine ruin
cerulean charm
#

you are still trying to cast None into a float, that is not possible

alpine ruin
#

Calling float there doesn't make sense.

silver oyster
#

okay

cerulean charm
#

print returns None

silver oyster
cerulean charm
#

remove the cast

alpine ruin
#

Remove the call to float.

silver oyster
cerulean charm
#

πŸ‘

silver oyster
#

oh

alpine ruin
silver oyster
#

i'm impressed, and disappointed of myself

#

thanks for the help

alpine ruin
#

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.

silver oyster
#

where can I learn them better?

cerulean charm
#

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

alpine ruin
# silver oyster where can I learn them better?

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.

royal stirrupBOT
#
Python help channel closed

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.