Commit 5afe0f64 by BellCodeEditor

save project

parent 458d2f77
Showing with 29 additions and 8 deletions
i = 5 # 行 class Hero(object):
j = 3 # 列 def __init__(self,name):
# 使用变量i和j,代替乘法算式里面的元素,打印出单个乘法算式 self.level = 1
print(i,"x",j,"=",i*j) self.hp = 250
\ No newline at end of file self.attack = 40
self.name = name
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)
yase = Hero("亚瑟")
houyi = Hero("后裔")
yase.combat(houyi)
\ No newline at end of file
i=1
fori
for j in range(1,10): for j in range(1,10):
print(j,"x",i,"=",j*i,end=" | ") print(j,"x",i,"=",j*i,end=" | ")
\ No newline at end of file print()
\ No newline at end of file
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