相关疑难解决方法(0)

无论输入如何,Python函数都会运行到第一个if语句

我正在通过在线教程学习Python.我的问题是,当我运行脚本时,无论我输入什么响应,我得到的是if go =="kitchen"......

def go_to():
    go = raw_input("Go to? ")

    if go == Kitchen or breakfast:
         print "You rumble down stairs and into the kitchen. Your mom has left some microwaved waffles on the table for you. Your big boy step sits by the counter."
    elif go == "back to bed" or "back to sleep" or bed or sleep:
        print "You hit snooze and roll over."
    elif go == "bathroom" or "toilet" or "potty" or "pee" or "poop" or "take …
Run Code Online (Sandbox Code Playgroud)

python

3
推荐指数
1
解决办法
945
查看次数

无法从辅音中确定元音

使用下面的代码,无论输入的第一个字母是什么,它总是被确定为元音:

original = raw_input("Please type in a word: ")
firstLetter = original[0]
print firstLetter

if firstLetter == "a" or "e" or "i" or "o" or "u":
    print "vowel"
else:
    print "consonant"
Run Code Online (Sandbox Code Playgroud)

实际上,在if语句中布尔值是什么并不重要......如果它是==或!=,它仍然是返回"vowel".为什么?

python character

2
推荐指数
1
解决办法
5561
查看次数

标签 统计

python ×2

character ×1