2017-04-19 26 views
1

我把在打印語句的變量,我得到這個錯誤信息:Python變量

Traceback (most recent call last): 
    File "C:\Users\Samuel\workspace\First Python Project\com\fireboxtraining\Person.py", line 13, in <module> 
    print("Dude, %s is not yes or no... come on.") % (game) 
TypeError: unsupported operand type(s) for %: 'NoneType' and 'str' 

這是我的代碼:

''' 
Created on Apr 17, 2017 

@author: Samuel 
''' 
game = input("Would you like to play a game? Please answer with \"Yes\" or \"No\".") 
game = game.lower() 
if game == "yes": 
    print("Great! Let's play.") 
elif game == "no": 
    print("Ok, I guess we won't play.") 
else: 
    print("Dude, %s is not yes or no... come on.") %(game) 

我剛學蟒蛇,我不明白爲什麼這不起作用。請幫忙!

+0

你需要時,你不輸入任何答覆處理情況。值爲空白或無,因此打印它沒有意義。 – anonyXmous

+1

最後一行應該是'print(「夥計,%s不是是或不是......」%(遊戲))''。注意'print'右括號。 – pkuphy

回答

1

這是一個簡單的圓括號。您有:

print("Dude, %s is not yes or no... come on.") %(game) 

它應該是:

print("Dude, %s is not yes or no... come on." % (game))