meal_cost = 10.00
tax_rate = 0.08
tip_rate = 0.20
#You may modify the lines of code above, but don't move them!
#When you Submit your code, we'll change these lines to
#assign different values to the variables.
#When eating at a restaurant in the United States, it's
#customary to have two percentage-based surcharges added on
#top of your bill: sales tax and tip. These percentages are
#both applies to the original cost of the meal. For example,
#a 10.00 meal with 8% sales tax and 20% tip would add 0.80
#for tax (0.08 * 10.00) and 2.00 for tip (0.20 * 10.00).
#
#The variables above create the cost of a meal and identify
#what percentage should be charged for tax and tip.
#
#Add some code below that will print the "receipt" for a
#meal purchase. The receipt should look like this:
#
#Subtotal: 10.00
#Tax: 0.8
#Tip: 2.0
#Total: 12.8
#
#Subtotal is the original value of meal_cost, tax is the
#tax rate times the meal cost, the tip is the tip rate times
#the meal cost, and the total is the sum of all three numbers.
#Don't worry about the number of decimal places; it's fine
#if your code leaves off some numbers (like 0.8 for tax) or
#includes too many decimal places (like 2.121212121 for the tip).
#Add your code here!
Subtotal = print(float(meal_cost))
Tax= print(float(tax_rate*10))
Tip = print(float(tip_rate *100))
Total = print(Subtotal + Tax + Tip)
Total = print(Subtotal + Tax + Tip)
TypeError: unsupported operand type(s) for +: 'NoneType' and 'NoneType'
尽管我已经把所有的东西都转换成了float,但为什么我会得到这个错误呢
为什么添加float会导致这样的错误
无法使用print()分配语句
另外,您的变量已经是float,您不需要将它们放在float()中
这样做:
但是,如果要打印并同时在print()中指定变量(我不建议这样做),可以使用walrus运算符:
解决了它。感谢您的指导
相关问题 更多 >
编程相关推荐