TORONTO KIDS COMPUTER CLUB | Sunday 9:45 Python Homework 11.18.
15970

# Sunday 9:45 Python Homework 11.18.

## 20 Nov Sunday 9:45 Python Homework 11.18.

Question：

1.Try to modify the program we made in the class(please see the code below), make one more choice to show your game status, it includes the name of all heroes which you own with its level and the money you have, the display result could be as following:

You have Level 1 knight, Level 3 archer, Level 2 ranger, Level 1 commando
You have 25900 coins

##- you will be given choices as following:
## 1. fight
## 3. show heroes’ status
## 4. quit
##
##- you will gain coins buy fighting monsters
##- but you may get chance loose the battle
##- if you have enough coins, you can buy new hero or upgrade your
## existing hero
##- you will get more coins if your hero’s power gets higher

##- you will be given choices as following:
##     1. fight
##     3. show heroes" status
##     4. quit
##
##- you will gain coins buy fighting monsters
##- but you may get chance loose the battle
##- if you have enough coins, you can buy new hero or upgrade your
## existing hero
##- you will get more coins if your hero"s power gets higher

import random
lsMonster = ["skeleton", "goblin", "zombie", "demon", "dragon", "devil"]
lsMonsterPower = [50, 100, 200, 400, 800, 1600]

lsHero = ["knight", "archer", "barbarian", "pekka",
"wizard", "prince", "balloon", "lava hound",
"mega knight", "inferno dragon"]
lsHeroPower = [10, 15, 25, 50, 70, 100, 150, 200, 3000, 50000]
lsHeroLevel = [1,1,1]
lsHeroCost = [200, 300, 500, 800, 1200, 2000, 3000, 5000, 10000, 250000]
lsHeroOwn = ["knight", "archer", "barbarian"]

gold = 500
while True:
choice = input("\t1. fight \
\n\t3. show heroes status \
\n\t4. quit \

if choice == "1":
m = random.randint(0, 5)
h = random.randint(0, len(lsHeroOwn)-1)
i = lsHero.index(lsHeroOwn[h])
p = lsMonsterPower[m] + lsHeroPower[i]
print("your hero", lsHeroOwn[h], "will fight", lsMonster[m])
w = random.randint(1, p)
if w <= lsHeroPower[i]:
gold += p
print("You won the battle, and you got", p, "gold. Now you have", gold, "gold in total.")
else:
print("You lost the battle!")

elif choice == "2":
strUB = ""
for i in range(len(lsHero)):
strUB += str(i+1) + "- " + lsHero[i] + \
": " + str(lsHeroCost[i]) + " "
print(strUB)

# newly changed
if gold >= lsHeroCost[c]:
gold -= lsHeroCost[c]
if lsHero[c] in lsHeroOwn:
i = lsHeroOwn.index(lsHero[c])
lsHeroLevel[i] += 1
lsHeroPower[i] = int(lsHeroPower[i] * 1.2)
print(lsHero[c], "is now level", lsHeroLevel[lsHeroOwn.index(lsHero[c])])
else:
lsHeroOwn.append(lsHero[c])
lsHeroLevel.append(1)
print("Congrats! You got new hero", lsHero[c])
else:
print("You do not have enough money") # newly add

if choice == "3":
# Homework start from here