# set values to abc & cde
abc = "text1"
cde = "text2"
# your code as is
a=raw_input("Enter Your Name") #raw_input() for Py2.x, input() for Py3.x
if a==abc:
print "5478"
if a==cde:
print "5479"
或者
更改if条件,将abc&;cde放在引号中
a=raw_input("Enter Your Name") #raw_input() for Py2.x, input() for Py3.x
if a=="abc": # added quotes to abc
print "5478"
if a=="cde": # added quotes to cde
print "5479"
有两种方法可以解决此问题:
将值设置为
abc
&;cde
或者
更改if条件,将
abc
&;cde
放在引号中将abc改为“abc”。它试图比较变量a和变量abc。你知道吗
有两个错误,第一个是来自print语句
print "456"
似乎您使用的是Python2.x,第二个错误是使用input()
从用户获取输入,如果您确实使用Python2.x,则必须使用raw_input()
;第二个错误是在比较输入时,必须将输入与str
而不是未初始化的变量进行比较。你知道吗相关问题 更多 >
编程相关推荐