Skip to main content
 首页 » 编程设计

python之elif 只触发 if 语句

2025年05月04日15over140

<分区>

使用 python 2.7.5

x = (raw_input)'''What will you Reply? 
a. Nod 
b. Answer 
c. Stare 
''')) 
 
if x == "Nod" or "a" or "nod": 
    print '''You nod shyly. 
"Oh that's Great"''' 
elif x == "Answer" or "b" or "answer": 
    print '''You answer in a low tone. 
"You can speak!"''' 
elif x == "Stare" or "c" or "stare": 
    print '''you stare blankly, so does the AI. 
"Well okay then."''' 

然后当我运行它时,无论我在提示符中输入什么,它只会触发'''你害羞地点点头。 “哦,太好了”'''

但是,如果我复制它并将其粘贴到我的 python shell 中,它会出现“Oh”的问题,如果我去掉它,它就会出现“That's”中的 t 问题,如果我只是去掉“太棒了”下一个elif语句的前三个字符有问题。 WTF 错了,我的 python 代码和 shell 最近工作正常,能够拆分 if 和 elif。但现在突然间它不想了。