在理论上:当调用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()
的值。
谁能告诉我这里缺少什么?
bootstrap-select.js
答案 0 :(得分:2)
看起来您的范围存在问题。
quiz_paragraph
中的set_difficulty
变量与'全球'不同。 quiz_paragraph
。虽然它们目前使用相同的名称,但您可以将set_difficulty
内的一个重命名为foo
,但结果会相同。
您需要设置全局' quiz_paragraph
返回set_difficulty
返回的值,或game_start
内更好的另一个局部变量。也就是说,
def game_start():
quiz_paragraph = set_difficulty(ask_difficulty())
print quiz_paragraph
或
def game_start():
my_difficulty = set_difficulty(ask_difficulty())
print my_difficulty