私はこのゲームのこのコードをユーザ入力を使って記述しましたが、動作していないようです。これは私のコードです。Pythonプログラミング:入力変数が名前エラーを返しています
import random
print ("Welcome to the hungry dog game.")
print ("The aim of this game is to save the hungry dog. How long can you keep it alive for?")
true = True
false = False
aliveordeadlist1 = [true, false]
random.choice(aliveordeadlist1)
feed1 = input("Ok so here's your first choice. Are you going to feed your dog now or not?(he doesn't look very hungry...) type in yes or no.")
if feed1 == "no" and aliveordeadlist1 == false:
print ("Well you were wrong, he was hungry. Your dog died sorry. Better luck next time.")
if feed1 == "yes" and aliveordeadlist1 == false:
print ("As I told you he wansn't hungry> You overfed him so hed died sorry. Better luck next time.");
if feed1 == "no" and aliveordeadlist1 == true:
print ("Well done he wasn't hungry. He is still alive (for now...)");
if feed1 == "yes" and aliveordeadlist1 == true:
print ("Well done he actually was hungry so he would have died if you didn't feed him.He is still alive (for now...)");
私は貝にし、例えば、このコードを実行すると、種類ははい、それはこのエラーを返します。
Traceback (most recent call last):
File "/Users/mac/Documents/hungrydoggame.py", line 16, in <module>
feed1 = input("Ok so here's your first choice. Are you going to feed your dog now or not?(he doesn't look very hungry...) type in yes or no.")
File "<string>", line 1, in <module>
NameError: name 'yes' is not defined
私はこのエラーを受けていると私は修正するために何をすべき理由を、私はわかりませんよ誰にも何か提案はありますか?
私のために働いてください。 –
'raw_input()'を使用 –