在理論值:當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)以獲得有關此主題的更多討論,因爲它被問了很多 –