Requirements:
1. Create three game characters, respectively:
Cang Jing, Female, 18, initial combat 1000
Tony Wood, Male, 20, initial combat 1800
Wave Toto, female, 19, initial combat 2500
2, the game scene, respectively:
Bush fights, consumes 200 combat power
Self-cultivation, increased 100 combat effectiveness
Multiplayer game, consumes 500 combat power
class Person: def __init__(self, name, gender, age, fight): self.name = name self.gender = gender self.age = age self.fight = fight def caocong(self): self.fight = self.fight - 200 def xiulian(self): self.fight = self.fight + 100 def duoren(self): self.fight = self.fight - 500 def show(self): print("%s %s %d %d" %(self.name, self.gender, self.age, self.fight))cang = Person("苍井井", "女", 18, 1000)dong = Person("东尼木木", "男", 20, 1800)bo = Person("波多多", "女", 19, 2500)cang.show()dong.show()bo.show()cang.caocong()dong.xiulian()bo.duoren()cang.show()dong.show()bo.show()运行结果:苍井井 女 18 1000东尼木木 男 20 1800波多多 女 19 2500苍井井 女 18 800东尼木木 男 20 1900波多多 女 19 2000
Python Exercises: Simple character Game program