0
你能檢查我的代碼,並請告訴我爲什麼NameError:name'Yes'未定義 發生。NameError發生在用戶輸入東西
"""This code prints how many tickets user gets depending on userDollar"""
FirstClassPrice = 44
userDollar = int(input("Please enter the number of dollars you want to
spend:"))
userDollarConvert = 100 * userDollar
userTick = userDollarConvert // FirstClassPrice
#Input and output of the code showing the change
userChange = userDollarConvert % FirstClassPrice
print("Your Change: $0." + str(userChange))
print("Number of First Class Tickets You Have:" + str(userTick))
#100 Tickets can be changed into 1 dinner ticket
if 100 <= userTick:
userChoice = input("Would you like to change 100 tickets into a free
dinner ticket? Yes or No only.")
if userChoice == ("Yes"):
DinnerTicket = 100(userTick)
print("You now have:" + DinnerTicket // userTick + "DinnerTicket(s)")
print("You have" + DinnerTicket % userTick + "Tickets remaining")
第3行和第17行提供了2個單獨的句子,因爲這些行太長而不適合問題欄謝謝! –
你在Python 2中,因此,你應該使用'raw_input'。在Python 2中輸入'''eval'是用戶輸入的字符串,這會導致你的錯誤。 –
他正在使用print(),所以它的python3不是python2 –