2016-11-24 43 views
0

我是新來的蟒蛇我想代碼這個,我問一個問題,因此「你是一個突變體」,並根據如果用戶回答是或否它應該來相應的輸出,但它只適用於yes,但不適用no。我如何讓它爲elif輸出工作?在Python中是或不是輸出

print("Are you a mutant?") 
answer = input() 
if 'Yes': 
    print("Your application to Xavier's School for Gifted Youngsters has been accepted") 
elif 'No': 
    print("Your application was not successful on this occassion") 

`

+1

嘗試做的,如果答案==「是」 –

+0

@OmidCompSCI感謝它的工作 – Anthony

+0

沒問題,如果你相信這個回答下面你的問題,請接受,以便其他人可以使用它作爲這個問題的參考。 –

回答

1

你需要存儲用戶輸入與您比較它的東西的變量進行比較。在這種情況下使用==。下面是修改後的代碼斷你的例子:

print("Are you a mutant?") 
answer = input() 
if answer == 'Yes': 
    print("Your application to Xavier's School for Gifted Youngsters has been accepted") 
elif answer == 'No': 
    print("Your application was not successful on this occassion")