参考下这个
gj = int(input("请输入攻击值:"))
fy = int(input("请输入防御值:"))
gjCount = gj // 10
print("攻击 " + "%d" % gj + " ", end="")
for i in range(gjCount):
print("*", end="")
print()
fyCount = fy // 10
print("防御 " + "%d" % fy + " ", end="")
for i in range(fyCount):
print("*", end="")
class Point():
#点的静态属性
def __init__(self,x,y):
self.x = x
self.y = y
# 移动到的点
def move_to(self,x,y):
self.x = x
self.y = y
# 移动了
def move_by(self,dx,dy):
self.x += dx
self.y += dy
def distance(self,other):
lens=((self.x - other.x)**2 + (self.y - other.y)**2)**0.5
return f'{lens:.2f}'
d1=Point(10,28)
d1.move_to(50,89) # 表示移动到这个点(50,89)
d1.move_by(10,10) # 表示在原坐标的基础上移动,移动后的点为(20,38)
class Line():
# start和end是练习一中的实例化对象
def __init__(self,start,end):
self.start = start
self.end = end
def length(self):
# 返回练习一中的距离方法
return self.start.distance(self.end)
def relationship(self,other):
# 给四个点
sx1, sy1, ex1, ey1 = self.start.x, self.start.y, self.end.x, self.end.y
sx2, sy2, ex2, ey2 = self.start.x, self.start.y, self.end.x, self.end.y
# 斜率法判断两条线之间的关系,斜率不等则相交
if (ey1-sy1)/(ex1-sx1) != (ey2-sy2)/(ex2-sx2):
print('相交')
else:
print('平行')
p1=Point(2,3)
p2=Point(4,5)
p3=Point(8,9)
p4=Point(10,12)
print(p3.distance(p4))
line1=Line(p1,p2)
line2=Line(p3,p4)
line1.relationship(line2)
import time
class Countdown():
def __init__(self,hour,minute,second):
self.hour = hour
self.minute = minute
self.second = second
# 展示时间信息
def show(self):
return f'{self.hour:0>2d}:{self.minute:0>2d}:{self.second:0>2d}'
# 退出终止方法
def over(self):
return self.hour != 0 or self.minute != 0 or self.second != 0
# 走时间
def run(self):
if self.over():
self.second -=1
if self.second<0:
self.second = 59
self.minute -=1
if self.minute <0:
self.minute = 59
self.hour -=1
# 调用部分
clock = Countdown(0,2,6)
print(clock.show())
while clock.over():
time.sleep(1) # 循环一次间隔一秒
clock.run() # 循环跑时间的方法
print(clock.show()) # 跑一次展示一次