这是错误
Traceback (most recent call last):
File "G:\Computer Science\Python\Car Salesman Program Example.py", line 16, in <module>
print ("The price of the car is now: "),(base * tax / 100)+(base*license /100)+ base + dealer_prep + destination_charge
TypeError: unsupported operand type(s) for /: 'str' and 'int'
这是程序
#Car salesman calculations program.
#The user enters the base price of the car and the program adds tax, license (which are both a percentage
#of the base price),dealer prep and destination charge. It then displays the final price.
base = input("What is the base price of the car? ")
tax = 7
license = 4
dealer_prep = 500
destination_charge = 1000
print ("The price of the car is now: "),(base * tax / 100)+(base*license /100)+ base + dealer_prep + destination_charge
答案 0 :(得分:1)
您正在连接字符串,&#34;价格......&#34;,整数。您需要使用str()函数将整数转换为字符串。
print ("The price of the car is now: "),
str( (base * tax / 100)+(base*license /100)+ base + dealer_prep + destination_charge )
答案 1 :(得分:0)
您的变量base
是一个字符串,因此您无法使用base
进行计算,直到将其转换为整数:
base = int(input("What is the base price of the car? "))