[英]python 2.7 name “x”not defined error after raw_input
My program should take user input of three integers and choose the highest valued odd number. 我的程序应接受三个整数的用户输入,然后选择值最高的奇数。
my code is: 我的代码是:
X = int (raw_input ('Enter intenger: '))
y = int (raw_input ( 'Enter intenger: '))
z = int (raw_input ('Enter intenger: '))
if x > y and x > z and x%2==1 :
print 'x'
elif y > z and y%2==1:
print 'y'
elif z >y and z%2==0 :
print 'z'
else:
print 'no odd numbers'
after being prompted to enter integers 3 times my error message is: 被提示输入整数3次后,我的错误消息是:
Traceback (most recent call last): 追溯(最近一次通话):
line 5, in 第5行
if x > y and x > z and x%2==1 :
NameError: name 'x' is not defined NameError:未定义名称“ x”
I've tried writing: 我试过写:
x = x
y = y
z = z
and bunch of other ideas as well and am not getting it. 以及其他一些想法,但没有得到。
thank you 谢谢
X = int (raw_input ('Enter intenger: '))
您在varialbe声明期间给了X
,但是在使用时使用x
Your issue is simply a typo: 您的问题只是一个错字:
change this: 改变这个:
X = int (raw_input ('Enter intenger: '))
to this: 对此:
x = int (raw_input ('Enter intenger: '))
Python variables are case sensitive so X
is not the same thing as x
Python变量区分大小写,因此
X
与x
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.