Commit c7c4ee23 by BellCodeEditor

auto save

parent a0fe0ce4
Showing with 42 additions and 30 deletions
class Hero:
def __init__(self, name):
self.name = name
self.level = 1
self.hp = 250
self.attack = 40
self.max_hp = self.hp
def combat(self, enemy): # 普通攻击
info1 = self.name+"对"+enemy.name+"发起进攻,"
info2 = "造成"+str(self.attack)+"点伤害,"
enemy.hp -= self.attack
if enemy.hp > 0:
info3 = enemy.name+"还剩下"+str(enemy.hp)+"血量"
info = info1+info2+info3
print(info)
else:
info3 = enemy.name+"阵亡,游戏结束"
info = info1+info2+info3
print(info)
exit()
# 创建玩家类
class Player(Hero):
def __init__(self,name):
super().__init__(name)
self.hp = 200
self.attack = 50
with open(r'c:\Users\EDY\Documents\lesson13-1\sales_list.txt','r',encoding='utf-8') as file:
a=file.readlines()
player = Player("后羿")
print("玩家的血量值为:",player.hp)
print("玩家的攻击力为:",player.attack)
# 整理数据
fin = []
for i in a: #用for...in...把每一行的数据遍历
data=i.split() #把字符串切分成更细的一个个的字符串
sum = 0
for sales in data[1:]:
sum = sum + int(sales)
result = data[0] + str(sum) + "\n"
fin.append(result)
# 写入结果
with open(r'c:\Users\EDY\Documents\lesson13-1\new_sales_list.txt','a',encoding='utf-8') as file:
file.writelines(fin)
\ No newline at end of file
王娇: 131悟空: 348诺依: 380小贝: 182李丽: 201宋扬: 107王明: 245李强: 164孙小白: 222苏琪: 137刘若若: 147刘阳: 226王胜男: 123王娇: 131悟空348
诺依380
小贝182
李丽201
宋扬107
王明245
李强164
孙小白222
苏琪137
刘若若147
刘阳226
王胜男123
王娇131
悟空348
诺依380
小贝182
李丽201
宋扬107
王明245
李强164
孙小白222
苏琪137
刘若若147
刘阳226
王胜男123
王娇131
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment