#makes a varible called name to identify the players name
name=input("Hello person, Whats your name?")
#prints their name
print("Hello", name)
#console asks the player if they want to play the game, if choice is "yes" then continue, else say "ok bye bye" (at the bottom!!)
print("Do you want to hear a story?", name)
choice=input("Yes, No?")
if choice==("yes" or "yes " or "Yes" or "Yes "):
print("Ok", name,", listen up")
print("There was once an old, old house at the top of a hill Sooooo high it was above the clouds")
housename=input("What do you want to call the house?")
print("The old,",housename,"was once owned by an old lady. You decide to go up to the", housename, ",you encounter a ghost in your path. You see a varitety of weapons beside you, an axe, sword and a bow.")
#asks the player if they want an axe sword or bow
choice3=input("Do you choose the axe, sword or bow?")
#if the choice is "bow" then proceed with this code
if choice3==("bow" or "Bow" or "bow " or "Bow "):
print("You equip the shoddy Bow, The bow feels as if it could snap any second.")
#sets the enemyshealth as 10
enemyhealth=int(10)
#makes a while loop to keep the battle going instead of 1 time.
while enemyhealth >= 1:
print("Take a shot!")
bowattack=input("Type attack to fire an arrow!")
if bowattack==("attack"):
import random
#randomiser for damage generator
damage = ["1", "2", "3", "4"]
damage2 = int(random.choice(damage))
enemyhealth = enemyhealth - damage2
print("The ghost took some damage. Enemys health:", enemyhealth)
else:
print("Are you sure you typed shoot?")
#if the enemys health gets below 1 print you killed the ghost, reward system! **this is what im having trouble with!!**
if enemyhealth <= 1:
print("You killed the Ghost!!")
print("You vanquished the ghost, you now collect a new weapon!")
#confirms the reward, either gives the player a shiny bow or a double shot bow.
import random
reward = ["Shiny bow", "Doubleshot bow"]
#randomiser for either reward
reward2 =(random.choice(reward)
#prints what weapon the player got
#THIS IS THE PROBLEM, ON THIS LINE
print("You got a:", reward2)
#pointless easteregg :D
elif choice==("maybe"):
print("You found an easter egg, congrats. PS this does nothing")
#if the player typed anything other than yes say ok bye bye.
else:
print("Ok, bye bye", name)
我完全清楚代码还没有其他2个用于ax或剑的if语句。我遇到麻烦的是用于杀死幽灵的奖励发生器。我认为这是一个缩进错误;它表示打印行的语法错误。
我知道这需要很多代码,但我真的很感激,如果可以帮我解决这个问题;如果你看到任何东西,我可以围绕它做一个快捷方式也会有所帮助。 我正在使用python 3.4.2!
答案 0 :(得分:4)
您在前一行中缺少右括号:
reward2 =(random.choice(reward)
应该是:
reward2 =(random.choice(reward))
答案 1 :(得分:1)
此外,行if choice==('yes' or 'yes ' or 'Yes' or 'Yes '):
无效。
试试这个:
if choice.strip().lower() == 'yes':
# whatever
strip
将删除空格。 lower
会将字符串放在小写
choice3