好的,我最近开始使用Python,而且我并不完全确定这段代码有什么问题。任何帮助将不胜感激。
编辑1:所以人们在文本而不是图片中要求实际的代码,所以在这里:
Budget = input("What is your budget? ")
cost_of_meal = Budget/30
print(cost_of_meal)
错误:
What is your budget? 100
Traceback (most recent call last):
File "C:/Users/Noor/PycharmProjects/untitled/Learning.py", line 3, in <module>
cost_for_meal = Budget/30
TypeError: unsupported operand type(s) for /: 'str' and 'int'
Process finished with exit code 1
答案 0 :(得分:3)
您需要将输入显式转换为整数,因为input
会返回一个字符串。
Budget = int(input("What is your budget? "))
或者,如果要将其转换为float
(以支持浮点输入),则需要在输入上调用float()
。