【发布时间】:2017-07-14 23:18:26
【问题描述】:
这是我写的那段代码:
#This is the first ever piece of code I/'m Writing here
#This calculates the value after applying GST
#Example: here we are applying on a smartphone costing 10000
Cost = input('Enter the MRP of device here ')
Tax = 0.12
Discount = 0.05
Cost = Cost + Cost * float(Tax)
Total = Cost + Cost * float(Discount)
print(Total)
每当我尝试执行代码时,它都会在输入后出现异常:
TypeError: can't multiply sequence by non-int of type 'float'
【问题讨论】:
-
简短回答:
input在 python3 中返回str。您必须将其转换为数字类型。您还可以在Tax和Discount附近致电float,但这些已经是floats,因此它们不会为您做任何事情
标签: python