在理论值:当game_start
被调用,用户输入'easy'
变量quiz_paragraph
应承担的easy_paragprah
为什么是我的变量设置自己“时,试图设置另一个变量包含字符串
值在现状:的quiz_paragraph
的值被设置为"
我可以验证user_difficulty
被正确设置和被适当地供给到'easy'
set_difficulty
。 if
语句运行但不会更改quiz_paragraph
的值。
谁能告诉我我在这里失踪了什么?
# Easy Paragraph
easy_paragraph = '''\n___1___ is a programming ___2___ used to solve simple and complex problems. ___1___ like
many languages can be used to display a message to a user using ___3___. Try it sometime.
To display this common message by typing ___3___ '___4___ World!' \n'''
# Init Variables
user_difficulty = ""
quiz_paragraph = ""
# Ask user difficulty
def ask_difficulty():
user_difficulty = raw_input("What difficulty level would you like? ")
return user_difficulty
# Difficulty sets returned Paragraph
def set_difficulty(difficulty):
if difficulty == "easy":
quiz_paragraph = easy_paragraph
return quiz_paragraph
else:
print '''Sorry, that is not a valid choice.'''
# Start the game
def game_start():
set_difficulty(ask_difficulty())
print quiz_paragraph
# Game Start Test
game_start()
为什么给它人downvote零倍的原因吗?你会认为他们会希望我们了解我们做错了什么? –
不是你的贬低选民,而是1)摆脱道歉的段落,因为它没有增加任何信息,这将有助于有类似问题的未来游客或谁可能回答你的问题的人。 2)您可以通过显示您在本网站和其他网站上搜索类似问题所获得的具体结果来改进您的问题。我不是在谈论扔掉诸如“我到处搜索,什么也没找到”等线条,而是再次***具体的结果。这个网站希望你会做一个详尽的搜索*以前*询问,并且有很高的标准。 –
同样没有人需要发表评论时,发布票或反对票通常导致几乎没有火焰战争。查看[meta site](https://meta.stackoverflow.com/questions/261173/how-do-we-avoid-downvotes-without-a-comment)以获得有关此主题的更多讨论,因为它被问了很多 –