Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 当用户输入某些内容时,会发生NameError_Python_Nameerror - Fatal编程技术网

Python 当用户输入某些内容时,会发生NameError

Python 当用户输入某些内容时,会发生NameError,python,nameerror,Python,Nameerror,你能检查我的代码并告诉我为什么NameError:name'Yes'没有定义吗 发生 “”“此代码根据userDollar打印用户获得的票证数量”“” FirstClassPrice=44 userDollar=int(输入(“请输入您想要的美元数 开支:)) userDollarConvert=100*userDollar userTick=userDollarConvert//FirstClassPrice #显示更改的代码的输入和输出 userChange=userDollarConver

你能检查我的代码并告诉我为什么NameError:name'Yes'没有定义吗 发生

“”“此代码根据userDollar打印用户获得的票证数量”“”
FirstClassPrice=44
userDollar=int(输入(“请输入您想要的美元数
开支:))
userDollarConvert=100*userDollar
userTick=userDollarConvert//FirstClassPrice
#显示更改的代码的输入和输出
userChange=userDollarConvert%FirstClassPrice
打印(“您的更改:$0.+str(userChange))
打印(“您拥有的头等舱车票数量:+str(userTick))
#100张票可以换成1张晚餐票

如果在Python2中为100,请尝试
raw\u input()
而不是
input()
。它返回一个字符串,而不是试图将输入作为代码进行求值。

第3行和第17行创建了两个单独的句子,因为这些行太长,无法放入问题栏中。谢谢!您使用的是Python2,因此,您应该使用
raw\u input
<代码>输入
在Python2
eval
s中,用户输入的字符串会导致错误。他正在使用print with(),因此它不是python3python2@AlexLucaci
print()
在Python2上仍然是有效的语法,尽管语义可能不同(例如,您可能无意中创建了一个
元组)。因此,仅仅因为
print
token后面有括号并不能保证您使用的是Python3。将来,在创建有关StackOverflow的新问题之前,请至少尝试通过谷歌搜索找到答案。上面的重复目标是我在逐字搜索你的标题时得到的第二个目标。第一个问题是另一个链接到同一个副本的问题。
"""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")