python 2.7名称“x”未在raw_input之后定义错误

时间:2017-11-03 18:32:43

标签: python python-2.7 variables

我的程序应该使用三个整数的用户输入并选择最高值的奇数。

我的代码是:

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'

提示输入整数3次后,我的错误信息是:

追踪(最近一次呼叫最后一次):

第5行,

if x > y and x > z and x%2==1 :

NameError:名称'x'未定义

我试过写:

x = x 

y = y

z = z

以及其他一些想法,但我没有得到它。

谢谢

2 个答案:

答案 0 :(得分:3)

X = int (raw_input ('Enter intenger: '))您在变量声明期间提供了X,但在使用时使用了x

答案 1 :(得分:0)

您的问题只是一个错字:

改变这个:

X = int (raw_input ('Enter intenger: '))

到此:

x = int (raw_input ('Enter intenger: '))

Python变量区分大小写,因此Xx

不同