我在print语句中放入一个变量,我收到此错误消息:
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)
我只是在学习python,我不明白为什么这不起作用。请帮忙!
答案 0 :(得分:1)
这是一个简单的括号。你有:
print("Dude, %s is not yes or no... come on.") %(game)
它应该是:
print("Dude, %s is not yes or no... come on." % (game) )