我是一個整體編程新手,在我的理解它的旅程中,具體來說,我試圖重新創建駱駝遊戲。到目前爲止,我所遵循的步驟指示我創建一個while循環,它將在變量done = False時保持循環。在循環內部,我被指示打印幾封選擇信件,最終會做不同的事情。目前,我試圖通過選擇選項Q退出程序,但每次我輸入Q和時間,我得到一個錯誤,然後輸入:如何使用字母從多選列表中進行選擇?
Traceback (most recent call last):
File "/home/pi/Desktop/wasteland_Game.py", line 15, in <module>
user_Choice = input("You decide to: ")
File "<string>", line 1, in <module>
NameError: name 'Q' is not defined
但是,如果我輸入「Q」包括引號,程序結束。在我的問題上:我如何才能得到沒有引號的字母,就像帶引號的字母一樣工作?
這也是我第一次在這裏發表問題,請原諒任何格式問題。
謝謝你在前進,
RavusFlapjack
Python版本2.7.9
print("Welcome to Wasteland!")
print("You escaped with a Pristine Deathclaw Egg and need to get to Diamond City!")
print("The Deathclaws want their egg back and are chasing you down!")
print("Survive your Wasteland Trek and outrun the Deathclaws!\n")
done = False
while not done:
print("A. Drink from your trusty canteen.")
print("B. Move ahead walking speed.")
print("C. Move ahead full spring.")
print("D. Stop and rest.")
print("E. Check your Pip-Boy for status.")
print("Q. Quit")
user_Choice = input("You decide to: ")
if user_Choice == "Q":
print("Nobody likes a quitter!")
done = True
謝謝你的幫助,這個問題馬上解決了! – RavusFlapjack