print('what is your name') spam=input() if spam==1: print('Hello') elif spam==2: print('howdy') else:
print('yes')
在上面这段代码中,即使你输入1,结果也是yes
因为spam=‘1’,input默认的将输入转化为字符串类型,数字1与字符‘1’是不相等的
改正后
print('what is your name') spam=input() if int(spam)==1: print('Hello') elif int(spam)==2: print('howdy') else:
print('yes')
这样就能运行正常了