输入语句的EOF错误

时间:2017-12-31 17:58:08

标签: python

distance = input("Distance travelled: ")
passengers = input("Number of people travelling: ")
extra = (distance - 1)
extraCharge = (extra * 2) 
cost = 3 + extraCharge 

if passengers > 4:
    charge = (cost / 2)
    cost = (cost + charge) 
print("Cost: " + (cost))

所以这是我的代码,无法弄清楚它有什么问题。有人能帮我吗?当我运行它时,它在第1行显示EOF错误

1 个答案:

答案 0 :(得分:-3)

您需要在输入时提及整数。

distance = int(input("Distance travelled: "))
passengers = int(input("Number of people travelling: "))

extra = (distance - 1)

extraCharge = (extra * 2) 

cost = 3 + extraCharge 

if passengers > 4:
   charge = (cost / 2)

   cost = (cost + charge) 

print("Cost: {}".format(cost))

示例输入:

7 for distance
7 for passengers

输出是:

Cost: 22.5