2017-06-16 74 views
0

我剛開始使用Python,我似乎無法得到這個腳本工作:「好天」的劇本

name = input('Enter your name in quotes: ') 
print 'Hello,' + name +'!' 
age = input('Please enter your age with no quotes: ') 
print 'Hi again, ' + name +'! I see you are' ,age, 'years old.' 
color = input('What is your favorite color, in quotes? ') 
print 'I like the color ' + color + ' too, ' + name + '!' 
good_day = input('Are you having a good day? Type "Yes" or "No" ') 
if good_day == Yes : 
    print 'That is good, ' + name + '!' 
else : 
    print 'I hope your day gets better, ' + name + '!' 

它正常工作,直到你回答這行:

good_day = input('Are you having a good day? Type "Yes" or "No" ') 

在此之後,它說:

Traceback (most recent call last): 
    File "/Users/mtreadwell/Desktop/getage.py", line 8, in <module> 
    if good_day == Yes : 
NameError: name 'Yes' is not defined 

請幫助解決這個錯誤!

+2

修復:'if good_day ==「是」'。另外,如果將'input'更改爲'raw_input',則不必要求用戶輸入他們的答案 – inspectorG4dget

+1

'if good_day ==「Yes」:'您發佈的代碼查找名爲'Yes'的變量,而且沒有。變量名和字符串是非常不同的東西。 – Prune

回答

2
if good_day == Yes : 

Yes是你的問題。它應該是字符串,"Yes"