2016-12-18 3 views
0

このプログラムは、彼の村の攻撃に復讐するために旅にトロールを渡すユーザーです。ユーザーが3つの質問に正しく答えない限り、トロールは彼が橋を渡ることはできません。各質問が正しく回答された場合、ユーザーはインベントリに追加されたアイテムで報酬を受けるでしょう。不正な回答ごとに何らかの形でユーザを処罰します。私のプログラムでは、健康被害は100ポイントから、最初の質問は25 HPの損失につながり、2番目の質問に対する誤った答えは35 HPの損失をもたらし、3番目の質問は45 HPの損失をもたらす。 質問に間違った回答があった場合、アイテムに報酬を与えないように、このプログラムを入手する必要があります。また、間違った答えごとにダメージを表示する必要があります。 は、ここで私がこれまで持っているものです。アイテムがまだ在庫に追加され、健康被害は表示されず、発生しません。

# Every Hero has A Villain 
# Program will demonstrate an inventory 
# Troll asks hero 3 questions 
# hero will be rewarded with an item to his inventory with every correct answer 
# with every incorrect answer, he will damaged increasingly with each question 

# create an empty tuple 
inventory =() 


# create health tuple 
health = 100 
damage1 = 25 
damage2 = 35 
damage3 = 45 

# variables for inventory 
item1 = ("shield",) 
item2 = ("armor",) 
item3 = ("healing potion","sword",) 



answer1 = "pluto" 
answer2 = "toothpaste" 
answer3 = "deer" 

print("You shall not pass, you must answer my three questions correctly to pass.") 
input("\n\nPress the enter key to get question 1.") 


print("What planet is now considered a dwarf planet?") 
if answer1 == "pluto": 
    input("Answer1: ") 
    inventory += item1 
    print(inventory) 
    input("\n\nPress the enter key to get question 2.") 





else: 
    answer1 != "pluto" 
    health -= damage1 
    print(health) 
    print("Hero got the question wrong, so he lost", damage1, "health.") 
    input("\n\nPress the enter key to get question 2.") 


print("What do you put on your toothbrush to brush your teeth?") 
if answer2 == "toothpaste": 
    input("Answer2: ") 
    inventory += item2 
    print(inventory) 
    input("\n\nPress the enter key to get question 3.") 




else: 
    answer2 != "toothpaste" 
    health -= damage2 
    print("Hero got the question wrong, so he lost", damage2, "health.") 
    print(health) 
    input("\n\nPress the enter key to get question 3.") 



print("What type of animal is Bambi?") 
if answer3 == "deer": 
    input("Answer3: ") 
    inventory += item3 
    print(inventory) 
    print("You may now cross the bridge, good luck on your quest.") 



else: 
    answer3 != "deer" 
    health -= damage3 
    print(health) 
    print("Hero got the question wrong, so he lost", damage3, "health.") 
    print("Game over.") 




input("\n\nPress the enter key to exit.") 

答えて

1

あなたは、あなたの質問は次のようにする必要があるので、それは、入力される前の答えをチェックしているように見える:

answer変数が何に設定されている
answer = input("What planet is now considered a dwarf planet?") 

次にユーザーの種類は、あなたが設定したanswer1answer2answer3変数を使用して、この答えが正しいかどうかを確認する必要があります。

if answer == answer1: 
    #input("Answer1: ") 
    inventory += item1 
    print(inventory) 
    input("\n\nPress the enter key to get question 2.") 

answer変数を既にユーザーの入力に設定しているので、入力を再入力する必要がないため、入力をコメントアウトしました。

だから、それぞれの質問には、このような何かお読みください:

if answer == answer1: 
    #input("Answer1: ") 
    inventory += item1 
    print(inventory) 
    input("\n\nPress the enter key to get question 2.") 
else: 
    #answer1 != "pluto" 
    health -= damage1 
    print(health) 
    print("Hero got the question wrong, so he lost", damage1, "health.") 
    input("\n\nPress the enter key to get question 2.") 

answer1 != "pluto"は意味がありませんが。 if answer == answer1で正しいかどうかはすでに確認済みです。そうでない場合は間違っているはずです。

希望すると助かります!

関連する問題