如果声明似乎忽略了elif声明。 (蟒蛇)

时间:2017-05-20 15:22:47

标签: python if-statement

hiya我对所有这些编程和论坛的东西都是全新的,我不完全知道我在做什么。我正在尝试我的第一个真正的项目,这意味着一个小小的对话。(关注最后编码的一部分)到目前为止我有

print('Hello my name is NATBNAT- pronounced Nat.Ben.nat')

import time
time.sleep(2)

human1 = input ('Whats your name if i may ask?')


import time
time.sleep(2) # Import time allows for a delay in response. In this situation it has been used to allow for a more 'human' response.

#The {} let's the '.format' at the end know when to insert 'human1'
print('{} ....Hmm nice name'.format(human1))

import time
time.sleep(1)

feeling1 = input("So {} how are you feeling? Unhappy? ok? or Happy?".format(human1)) #once the human has answered ^^^^ question then whatever was the answere will be Feeling1. e.g.

if(feeling1 == 'unhappy' or 'Unhappy'):
    print('oh chucks, is there anything i can do to make it better?')
elif(feeling1 == 'ok' or 'Ok'):
    print('OOO intresting 0_o . I usually only know the differance between yes/no on/off or happy/unhappy. Please tell me if your ok because you could be better or you just feel worn out') 
elif(feeling1 == 'Happy' or 'happy'):
    print(' Oh Good ol man ... boy i mean girl... wait... DOH! I dont have eyes or the understanding between Female or Male names -_-')
从没有错误的意义上来说它一切正常,但它只是说第一个' if'声明,即使我输入“确定”#39;或者“快乐”。 请原谅这些笔记,因为它们只是为了给我自己提醒。谢谢:))

1 个答案:

答案 0 :(得分:3)

if(feeling1 == 'unhappy' or 'Unhappy')不符合您的期望。它应该是这样的:

if feeling1 == 'unhappy' or feeling1 == 'Unhappy':

或者你可以这样做:

if feeling1 in ('unhappy','Unhappy',):