2017-05-20 29 views
0

hiya我對所有這些編程和論壇的東西都是全新的,我不完全知道我在做什麼。我只是想嘗試我的第一個真正的項目,這是一個小對話。編碼)到目前爲止,我已經如果陳述似乎忽略elif語句。 (python)

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 -_-') 

它在某種意義上都工作正常,有沒有錯誤,但它只是說第一個「如果」語句,即使我輸入「OK」或「高興」。 請原諒,因爲他們只是爲了提醒自己。謝謝:)

回答

3

if(feeling1 == 'unhappy' or 'Unhappy')不會做你所期待的。它應該是這樣的:

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

或者你可以這樣做:

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

完美非常感謝你。從來不知道它會很快得到回答:D – SKEthan