【发布时间】:2019-09-21 19:05:31
【问题描述】:
我需要根据用户输入和使用数组来计算成本。我有以下代码,但不断收到错误(指向我的“打印”括号)。
您知道我可能缺少什么,以及是否可以使用更好的数组吗?
#route type
yourUserInput = input("will you use route 1 or 2 ")
finance = 1 #
if yourUserInput == "1":
finance = 25
elif yourUserInput == "2":
finance = 35
else:
print("you did not enter a valid route")
print ("total cost" (cost))
# ticket type
tickettype = input("what type of ticket would you like (single or return) ")
price = 1 #
if tickettype == "single" or tickettype == "Single":
price = 25
elif tickettype == "return" or tickettype == "Return":
price = 35
else:
print("you did not enter a valid ticket type")
#cost = int( finance ) *int( price )
ar= (finance + price)
#print "the total is therefore",
print ("your total price is" int(ar))
input("press enter to exit the program")
【问题讨论】:
-
print()语句中缺少逗号。 -
数组在哪里?无论如何,请尝试: print ("your total price is", ar) 即在要打印的字符串和变量之间缺少逗号。
-
如何添加数组?
-
您应该 read this article 了解如何在 Python 中打印字符串。
标签: python arrays input calculator