python编程代码画哆啦A梦(哆啦a梦编程图)

http://www.itjxue.com  2023-03-30 19:43  来源:未知  点击次数: 

Python作图程序

实战小程序:画出y=x^3的散点图

样例代码如下:

[python]?view plain?copy

#coding=utf-8

import?pylab?as?y????#引入pylab模块

x?=?y.np.linspace(-10,?10,?100)??#设置x横坐标范围和点数

y.plot(x,?x*x*x,'or')??#生成图像

ax?=?y.gca()

ax.spines['right'].set_color('none')

ax.spines['top'].set_color('none')

ax.xaxis.set_ticks_position('bottom')

ax.spines['bottom'].set_position(('data',?0))

ax.yaxis.set_ticks_position('left')

ax.spines['left'].set_position(('data',?0))

ax.set_yticks([-1000,?-500,?500,?1000])

y.xlim(x.min()?,?x.max()?)?#将横坐标设置为x的最大值和最小值

y.show()?#显示图像

[python]?view plain?copy

import?pylab?as?y

程序中引入的pylab属于matplotlib的一个模块,将其名字用y代替,其中包括了许多NumPy和pyplot模块中常用的函数,方便用户快速进行计算和绘图,十分适合在IPython交互式环境中使用。

[python]?view plain?copy

y.np.linspace(-10,?10,?100)

此为numpy中的一个函数,返回的是等间距的值,numpy.linspace(a,b,c):a指的是开始位置,b表示的是结束位置,c表示产生点的个数(默认为50)

举例:

[python]?view plain?copy

?np.linspace(2.0,?3.0,?num=5)

array([?2.??,??2.25,??2.5?,??2.75,??3.??])

[python]?view plain?copy

y.plot(x,?x*x*x,'or')??#生成图像

后面加上‘o'表示为散点图

'r'可设置颜色为红色,基本上和matlab的操作很像。

[python]?view plain?copy

y.xlim(x.min(),?x.max())

这条语句使用了xlim函数,将横坐标设置为x的大小

用Python画图

今天开始琢磨用Python画图,没使用之前是一脸懵的,我使用的开发环境是Pycharm,这个输出的是一行行命令,这个图画在哪里呢?

搜索之后发现,它会弹出一个对话框,然后就开始画了,比如下图

第一个常用的库是Turtle,它是Python语言中一个很流行的绘制图像的函数库,这个词的意思就是乌龟,你可以想象下一个小乌龟在一个x和y轴的平面坐标系里,从原点开始根据指令控制,爬行出来就是绘制的图形了。

??它最常用的指令就是旋转和移动,比如画个圆,就是绕着圆心移动;再比如上图这个怎么画呢,其实主要就两个命令:

turtle.forward(200)

turtle.left(170)

第一个命令是移动200个单位并画出来轨迹

第二个命令是画笔顺时针转170度,注意此时并没有移动,只是转角度

然后呢? 循环重复就画出来这个图了

好玩吧。

有需要仔细研究的可以看下这篇文章 ,这个牛人最后用这个库画个移动的钟表,太赞了。

Turtle虽好玩,但是我想要的是我给定数据,然后让它画图,这里就找到另一个常用的画图的库了。

Matplotlib是python最著名的绘图库,它提供了一整套和matlab相似的命令API,十分适合交互式地行制图。其中,matplotlib的pyplot模块一般是最常用的,可以方便用户快速绘制二维图表。

使用起来也挺简单,

首先import matplotlib.pyplot as plt?导入画图的图。

然后给定x和y,用这个命令plt.plot(x, y)就能画图了,接着用plt.show()就可以把图形展示出来。

接着就是各种完善,比如加标题,设定x轴和y轴标签,范围,颜色,网格等等,在 这篇文章里介绍的很详细。

现在互联网的好处就是你需要什么内容,基本上都能搜索出来,而且还是免费的。

我为什么要研究这个呢?当然是为了用,比如我把比特币的曲线自己画出来可好?

假设现在有个数据csv文件,一列是日期,另一列是比特币的价格,那用这个命令画下:

这两列数据读到pandas中,日期为df['time']列,比特币价格为df['ini'],那我只要使用如下命令

plt.plot(df['time'], df['ini'])

plt.show()

就能得到如下图:

自己画的是不是很香,哈哈!

然后呢,我在上篇文章 中介绍过求Ahr999指数,那可不可以也放到这张图中呢?不就是加一条命令嘛

plt.plot(df['time'], df['Ahr999'])

图形如下:

但是,Ahr999指数怎么就一条线不动啊,?原来两个Y轴不一致,显示出来太怪了,需要用多Y轴,问题来了。

继续谷歌一下,把第二个Y轴放右边就行了,不过呢得使用多图,重新绘制

fig = plt.figure() # 多图

ax1 = fig.add_subplot(111)

ax1.plot(df['time'], df['ini'], label="BTC price")? #?绘制第一个图比特币价格

ax1.set_ylabel('BTC price') #?加上标签

# 第二个直接对称就行了

ax2 = ax1.twinx()#?在右边增加一个Y轴

ax2.plot(df['time'], df['Ahr999'], 'r', label="ahr999")??#?绘制第二个图Ahr999指数,红色

ax2.set_ylim([0, 50])# 设定第二个Y轴范围

ax2.set_ylabel('ahr999')

plt.grid(color="k", linestyle=":")# 网格

fig.legend(loc="center")#图例

plt.show()

跑起来看看效果,虽然丑了点,但终于跑通了。

这样就可以把所有指数都绘制到一张图中,等等,三个甚至多个Y轴怎么加?这又是一个问题,留给爱思考爱学习的你。

有了自己的数据,建立自己的各个指数,然后再放到图形界面中,同时针对异常情况再自动进行提醒,比如要抄底了,要卖出了,用程序做出自己的晴雨表。

急求! 1,修改下列Python程序 print("Hello Python") 使其输出图形: * *** ***** ******* *********

第2题

程序1:

if num1+num2==int(answer):

程序2:

grade=int(input("输入成绩:"))

第三题:

将for语句修改下就可以

for i in range(0,100,2):#100以内的偶数,那就是不包含100了

第四题

这边选项数100

sum=0

for i in range(3,101,2):

? ?print i

? ?sum+=1.0/i

pi = 4*sum

print("the PI is ",pi)

第五题 已知三边求角,可用余弦定理求得,先列出公式,已知三边判断是否能构成三角形可用2边之和大于第三边求得。余弦定理公式如下

cosa=(b^2+c^2-a^2)/2bc

cosb=(a^2+c^2-b^2)/2ac

cosc=(a^2+b^2-c^2)/2ab

程序代码

values?=?[a,b,c]

max_value?=?max(values)

if?sum(values.remove(max_value))max_value:#2边之和大于第三边

????cosa?=?(b*b+c*c-a*a)/(2*b*c)

????cosb??=?(a*a+c*c-b*b)/(2*a*c)

????cosc?=?(a*a+b*b-c*c)/(2*a*b)

????import?math

????print?'a=',math.acos(cosa)

????print?'b=',math.acos(cosb)

????print?'c=',math.acos(cosc)

第六题

#?add?function?defined?by?user

def?add(n):

????s=0

????if?n2:

????????return?False

????if?n==2:

????????return?True

????for?i?in?range(1,n/2,1):

????????if?n%i==0:

????????????return?False

????return?True

#?calling?the?add?function

m=100

print?add(m)

Python turtle海龟制图 求代码

# coding:utf-8

import turtle as t

# 绘制小猪佩奇

# =======================================

t.pensize(4)

t.hideturtle()

t.colormode(255)

t.color((255, 155, 192), "pink")

t.setup(840, 500)

t.speed(10)

# 鼻子

t.pu()

t.goto(-100, 100)

t.pd()

t.seth(-30)

t.begin_fill()

a = 0.4

for i in range(120):

if 0 = i 30 or 60 = i 90:

a = a + 0.08

t.lt(3) # 向左转3度

t.fd(a) # 向前走a的步长

else:

a = a - 0.08

t.lt(3)

t.fd(a)

t.end_fill()

t.pu()

t.seth(90)

t.fd(25)

t.seth(0)

t.fd(10)

t.pd()

t.pencolor(255, 155, 192)

t.seth(10)

t.begin_fill()

t.circle(5)

t.color(160, 82, 45)

t.end_fill()

t.pu()

t.seth(0)

t.fd(20)

t.pd()

t.pencolor(255, 155, 192)

t.seth(10)

t.begin_fill()

t.circle(5)

t.color(160, 82, 45)

t.end_fill()

# 头

t.color((255, 155, 192), "pink")

t.pu()

t.seth(90)

t.fd(41)

t.seth(0)

t.fd(0)

t.pd()

t.begin_fill()

t.seth(180)

t.circle(300, -30)

t.circle(100, -60)

t.circle(80, -100)

t.circle(150, -20)

t.circle(60, -95)

t.seth(161)

t.circle(-300, 15)

t.pu()

t.goto(-100, 100)

t.pd()

t.seth(-30)

a = 0.4

for i in range(60):

if 0 = i 30 or 60 = i 90:

a = a + 0.08

t.lt(3) # 向左转3度

t.fd(a) # 向前走a的步长

else:

a = a - 0.08

t.lt(3)

t.fd(a)

t.end_fill()

# 耳朵

t.color((255, 155, 192), "pink")

t.pu()

t.seth(90)

t.fd(-7)

t.seth(0)

t.fd(70)

t.pd()

t.begin_fill()

t.seth(100)

t.circle(-50, 50)

t.circle(-10, 120)

t.circle(-50, 54)

t.end_fill()

t.pu()

t.seth(90)

t.fd(-12)

t.seth(0)

t.fd(30)

t.pd()

t.begin_fill()

t.seth(100)

t.circle(-50, 50)

t.circle(-10, 120)

t.circle(-50, 56)

t.end_fill()

# 眼睛

t.color((255, 155, 192), "white")

t.pu()

t.seth(90)

t.fd(-20)

t.seth(0)

t.fd(-95)

t.pd()

t.begin_fill()

t.circle(15)

t.end_fill()

t.color("black")

t.pu()

t.seth(90)

t.fd(12)

t.seth(0)

t.fd(-3)

t.pd()

t.begin_fill()

t.circle(3)

t.end_fill()

t.color((255, 155, 192), "white")

t.pu()

t.seth(90)

t.fd(-25)

t.seth(0)

t.fd(40)

t.pd()

t.begin_fill()

t.circle(15)

t.end_fill()

t.color("black")

t.pu()

t.seth(90)

t.fd(12)

t.seth(0)

t.fd(-3)

t.pd()

t.begin_fill()

t.circle(3)

t.end_fill()

# 腮

t.color((255, 155, 192))

t.pu()

t.seth(90)

t.fd(-95)

t.seth(0)

t.fd(65)

t.pd()

t.begin_fill()

t.circle(30)

t.end_fill()

# 嘴

t.color(239, 69, 19)

t.pu()

t.seth(90)

t.fd(15)

t.seth(0)

t.fd(-100)

t.pd()

t.seth(-80)

t.circle(30, 40)

t.circle(40, 80)

# 身体

t.color("red", (255, 99, 71))

t.pu()

t.seth(90)

t.fd(-20)

t.seth(0)

t.fd(-78)

t.pd()

t.begin_fill()

t.seth(-130)

t.circle(100, 10)

t.circle(300, 30)

t.seth(0)

t.fd(230)

t.seth(90)

t.circle(300, 30)

t.circle(100, 3)

t.color((255, 155, 192), (255, 100, 100))

t.seth(-135)

t.circle(-80, 63)

t.circle(-150, 24)

t.end_fill()

# 手

t.color((255, 155, 192))

t.pu()

t.seth(90)

t.fd(-40)

t.seth(0)

t.fd(-27)

t.pd()

t.seth(-160)

t.circle(300, 15)

t.pu()

t.seth(90)

t.fd(15)

t.seth(0)

t.fd(0)

t.pd()

t.seth(-10)

t.circle(-20, 90)

t.pu()

t.seth(90)

t.fd(30)

t.seth(0)

t.fd(237)

t.pd()

t.seth(-20)

t.circle(-300, 15)

t.pu()

t.seth(90)

t.fd(20)

t.seth(0)

t.fd(0)

t.pd()

t.seth(-170)

t.circle(20, 90)

# 脚

t.pensize(10)

t.color((240, 128, 128))

t.pu()

t.seth(90)

t.fd(-75)

t.seth(0)

t.fd(-180)

t.pd()

t.seth(-90)

t.fd(40)

t.seth(-180)

t.color("black")

t.pensize(15)

t.fd(20)

t.pensize(10)

t.color((240, 128, 128))

t.pu()

t.seth(90)

t.fd(40)

t.seth(0)

t.fd(90)

t.pd()

t.seth(-90)

t.fd(40)

t.seth(-180)

t.color("black")

t.pensize(15)

t.fd(20)

# 尾巴

t.pensize(4)

t.color((255, 155, 192))

t.pu()

t.seth(90)

t.fd(70)

t.seth(0)

t.fd(95)

t.pd()

t.seth(0)

t.circle(70, 20)

t.circle(10, 330)

t.circle(70, 30)

t.done()

python皮卡丘编程代码

import turtle

def getPosition(x, y):

turtle.setx(x)

turtle.sety(y)

print(x, y)

class Pikachu:

def __init__(self):

self.t = turtle.Turtle()

t = self.t

t.pensize(3)

t.speed(9)

t.ondrag(getPosition)

def noTrace_goto(self, x, y):

self.t.penup()

self.t.goto(x, y)

self.t.pendown()

def leftEye(self, x, y):

self.noTrace_goto(x, y)

t = self.t

t.seth(0)

t.fillcolor('#333333')

t.begin_fill()

t.circle(22)

t.end_fill()

self.noTrace_goto(x, y+10)

t.fillcolor('#000000')

t.begin_fill()

t.circle(10)

t.end_fill()

self.noTrace_goto(x+6, y + 22)

t.fillcolor('#ffffff')

t.begin_fill()

t.circle(10)

t.end_fill()

def rightEye(self, x, y):

self.noTrace_goto(x, y)

t = self.t

t.seth(0)

t.fillcolor('#333333')

t.begin_fill()

t.circle(22)

t.end_fill()

self.noTrace_goto(x, y+10)

t.fillcolor('#000000')

t.begin_fill()

t.circle(10)

t.end_fill()

self.noTrace_goto(x-6, y + 22)

t.fillcolor('#ffffff')

t.begin_fill()

t.circle(10)

t.end_fill()

def mouth(self, x, y):

self.noTrace_goto(x, y)

t = self.t

t.fillcolor('#88141D')

t.begin_fill()

# 下嘴唇

l1 = []

l2 = []

t.seth(190)

a = 0.7

for i in range(28):

a += 0.1

t.right(3)

t.fd(a)

l1.append(t.position())

self.noTrace_goto(x, y)

t.seth(10)

a = 0.7

for i in range(28):

a += 0.1

t.left(3)

t.fd(a)

l2.append(t.position())

# 上嘴唇

t.seth(10)

t.circle(50, 15)

t.left(180)

t.circle(-50, 15)

t.circle(-50, 40)

t.seth(233)

t.circle(-50, 55)

t.left(180)

t.circle(50, 12.1)

t.end_fill()

# 舌头

self.noTrace_goto(17, 54)

t.fillcolor('#DD716F')

t.begin_fill()

t.seth(145)

t.circle(40, 86)

t.penup()

for pos in reversed(l1[:20]):

t.goto(pos[0], pos[1]+1.5)

for pos in l2[:20]:

t.goto(pos[0], pos[1]+1.5)

t.pendown()

t.end_fill()

# 鼻子

self.noTrace_goto(-17, 94)

t.seth(8)

t.fd(4)

t.back(8)

# 红脸颊

def leftCheek(self, x, y):

turtle.tracer(False)

t = self.t

self.noTrace_goto(x, y)

t.seth(300)

t.fillcolor('#DD4D28')

t.begin_fill()

a = 2.3

for i in range(120):

if 0 = i 30 or 60 = i 90:

a -= 0.05

t.lt(3)

t.fd(a)

else:

a += 0.05

t.lt(3)

t.fd(a)

t.end_fill()

turtle.tracer(True)

def rightCheek(self, x, y):

t = self.t

turtle.tracer(False)

self.noTrace_goto(x, y)

t.seth(60)

t.fillcolor('#DD4D28')

t.begin_fill()

a = 2.3

for i in range(120):

if 0 = i 30 or 60 = i 90:

a -= 0.05

t.lt(3)

t.fd(a)

else:

a += 0.05

t.lt(3)

t.fd(a)

t.end_fill()

turtle.tracer(True)

def colorLeftEar(self, x, y):

t = self.t

self.noTrace_goto(x, y)

t.fillcolor('#000000')

t.begin_fill()

t.seth(330)

t.circle(100, 35)

t.seth(219)

t.circle(-300, 19)

t.seth(110)

t.circle(-30, 50)

t.circle(-300, 10)

t.end_fill()

def colorRightEar(self, x, y):

t = self.t

self.noTrace_goto(x, y)

t.fillcolor('#000000')

t.begin_fill()

t.seth(300)

t.circle(-100, 30)

t.seth(35)

t.circle(300, 15)

t.circle(30, 50)

t.seth(190)

t.circle(300, 17)

t.end_fill()

def body(self):

t = self.t

t.fillcolor('#F6D02F')

t.begin_fill()

# 右脸轮廓

t.penup()

t.circle(130, 40)

t.pendown()

t.circle(100, 105)

t.left(180)

t.circle(-100, 5)

# 右耳朵

t.seth(20)

t.circle(300, 30)

t.circle(30, 50)

t.seth(190)

t.circle(300, 36)

# 上轮廓

t.seth(150)

t.circle(150, 70)

# 左耳朵

t.seth(200)

t.circle(300, 40)

t.circle(30, 50)

t.seth(20)

t.circle(300, 35)

#print(t.pos())

# 左脸轮廓

t.seth(240)

t.circle(105, 95)

t.left(180)

t.circle(-105, 5)

# 左手

t.seth(210)

t.circle(500, 18)

t.seth(200)

t.fd(10)

t.seth(280)

t.fd(7)

t.seth(210)

t.fd(10)

t.seth(300)

t.circle(10, 80)

t.seth(220)

t.fd(10)

t.seth(300)

t.circle(10, 80)

t.seth(240)

t.fd(12)

t.seth(0)

t.fd(13)

t.seth(240)

t.circle(10, 70)

t.seth(10)

t.circle(10, 70)

t.seth(10)

t.circle(300, 18)

t.seth(75)

t.circle(500, 8)

t.left(180)

t.circle(-500, 15)

t.seth(250)

t.circle(100, 65)

# 左脚

t.seth(320)

t.circle(100, 5)

t.left(180)

t.circle(-100, 5)

t.seth(220)

t.circle(200, 20)

t.circle(20, 70)

t.seth(60)

t.circle(-100, 20)

t.left(180)

t.circle(100, 20)

t.seth(300)

t.circle(10, 70)

t.seth(60)

t.circle(-100, 20)

t.left(180)

t.circle(100, 20)

t.seth(10)

t.circle(100, 60)

# 横向

t.seth(180)

t.circle(-100, 10)

t.left(180)

t.circle(100, 10)

t.seth(5)

t.circle(100, 10)

t.circle(-100, 40)

t.circle(100, 35)

t.left(180)

t.circle(-100, 10)

# 右脚

t.seth(290)

t.circle(100, 55)

t.circle(10, 50)

t.seth(120)

t.circle(100, 20)

t.left(180)

t.circle(-100, 20)

t.seth(0)

t.circle(10, 50)

t.seth(110)

t.circle(100, 20)

t.left(180)

t.circle(-100, 20)

t.seth(30)

t.circle(20, 50)

t.seth(100)

t.circle(100, 40)

# 右侧身体轮廓

t.seth(200)

t.circle(-100, 5)

t.left(180)

t.circle(100, 5)

t.left(30)

t.circle(100, 75)

t.right(15)

t.circle(-300, 21)

t.left(180)

t.circle(300, 3)

# 右手

t.seth(43)

t.circle(200, 60)

t.right(10)

t.fd(10)

t.circle(5, 160)

t.seth(90)

t.circle(5, 160)

t.seth(90)

t.fd(10)

t.seth(90)

t.circle(5, 180)

t.fd(10)

t.left(180)

t.left(20)

t.fd(10)

t.circle(5, 170)

t.fd(10)

t.seth(240)

t.circle(50, 30)

t.end_fill()

self.noTrace_goto(130, 125)

t.seth(-20)

t.fd(5)

t.circle(-5, 160)

t.fd(5)

# 手指纹

self.noTrace_goto(166, 130)

t.seth(-90)

t.fd(3)

t.circle(-4, 180)

t.fd(3)

t.seth(-90)

t.fd(3)

t.circle(-4, 180)

t.fd(3)

# 尾巴

self.noTrace_goto(168, 134)

t.fillcolor('#F6D02F')

t.begin_fill()

t.seth(40)

t.fd(200)

t.seth(-80)

t.fd(150)

t.seth(210)

t.fd(150)

t.left(90)

t.fd(100)

t.right(95)

t.fd(100)

t.left(110)

t.fd(70)

t.right(110)

t.fd(80)

t.left(110)

t.fd(30)

t.right(110)

t.fd(32)

t.right(106)

t.circle(100, 25)

t.right(15)

t.circle(-300, 2)

##############

#print(t.pos())

t.seth(30)

t.fd(40)

t.left(100)

t.fd(70)

t.right(100)

t.fd(80)

t.left(100)

t.fd(46)

t.seth(66)

t.circle(200, 38)

t.right(10)

t.fd(10)

t.end_fill()

# 尾巴花纹

t.fillcolor('#923E24')

self.noTrace_goto(126.82, -156.84)

t.begin_fill()

t.seth(30)

t.fd(40)

t.left(100)

t.fd(40)

t.pencolor('#923e24')

t.seth(-30)

t.fd(30)

t.left(140)

t.fd(20)

t.right(150)

t.fd(20)

t.left(150)

t.fd(20)

t.right(150)

t.fd(20)

t.left(130)

t.fd(18)

t.pencolor('#000000')

t.seth(-45)

t.fd(67)

t.right(110)

t.fd(80)

t.left(110)

t.fd(30)

t.right(110)

t.fd(32)

t.right(106)

t.circle(100, 25)

t.right(15)

t.circle(-300, 2)

t.end_fill()

# 帽子、眼睛、嘴巴、脸颊

self.cap(-134.07, 147.81)

self.mouth(-5, 25)

self.leftCheek(-126, 32)

self.rightCheek(107, 63)

self.colorLeftEar(-250, 100)

self.colorRightEar(140, 270)

self.leftEye(-85, 90)

self.rightEye(50, 110)

t.hideturtle()

def cap(self, x, y):

self.noTrace_goto(x, y)

t = self.t

t.fillcolor('#CD0000')

t.begin_fill()

t.seth(200)

t.circle(400, 7)

t.left(180)

t.circle(-400, 30)

t.circle(30, 60)

t.fd(50)

t.circle(30, 45)

t.fd(60)

t.left(5)

t.circle(30, 70)

t.right(20)

t.circle(200, 70)

t.circle(30, 60)

t.fd(70)

# print(t.pos())

t.right(35)

t.fd(50)

t.circle(8, 100)

t.end_fill()

self.noTrace_goto(-168.47, 185.52)

t.seth(36)

t.circle(-270, 54)

t.left(180)

t.circle(270, 27)

t.circle(-80, 98)

t.fillcolor('#444444')

t.begin_fill()

t.left(180)

t.circle(80, 197)

t.left(58)

t.circle(200, 45)

t.end_fill()

self.noTrace_goto(-58, 270)

t.pencolor('#228B22')

t.dot(35)

self.noTrace_goto(-30, 280)

t.fillcolor('#228B22')

t.begin_fill()

t.seth(100)

t.circle(30, 180)

t.seth(190)

t.fd(15)

t.seth(100)

t.circle(-45, 180)

t.right(90)

t.fd(15)

t.end_fill()

t.pencolor('#000000')

def start(self):

self.body()

def main():

print('Painting the Pikachu... ')

turtle.screensize(800, 600)

turtle.title('Pikachu')

pikachu = Pikachu()

pikachu.start()

turtle.mainloop()

if __name__ == '__main__':

main()

PYTHON 程序问题?

import re

fatloss = "\nGym workout for fat loss\n\nPlate thrusters (15 reps x 3 sets)\nMountain climbers (20 reps x 3 sets)\nBox jumps (10 reps x 3 sets)\nLounges (10 reps x 3 sets)\nRenegade rows (10 reps x 3 sets)\nPress ups (15 reps x 3 sets)\nTreadmill (15 mins x 2 sets)\nSupermans (15 reps x 3 sets)\nCrunches (20 reps x 3 sets)"

# fatloss.split('\n')

# print(fatloss)

find_all = re.findall(r'.*?[(]',fatloss)

exercise = []

for i in find_all:

exercise.append(i.replace(' (','').lower())

# print(exercise)

num = re.findall("\d+",fatloss)

reps_list = []

sets_list = []

for i in range(len(num)):

if i%2 == 0:

reps_list.append(int(num[i]))

else:

sets_list.append(int(num[i]))

x_list = []

for i in range(len(reps_list)):

x_list.append(reps_list[i] * sets_list[i])

# print(x_list)

x_dict = dict(zip(exercise,x_list))

# print(x_dict)

def answer(x,a):

if 60 a = 65:

ans = x*(1-1/100*(a-60))

elif a = 75:

ans = x*(1-5/100-2/100*(a-65))

elif a = 80:

ans = x*(1-25/100-3/100*(a-75))

if a 80 or 40/100+4/100*(a-80) 80 :

ans = min((40/100+4/100 *(a-80)),80)

return ans

e = input('enter the exercise you want to do:').lower()

x = x_dict.get(e)

a = int(input('enter your age:'))

ans = answer(x,a)

feedback = f'The extraction of {e.title()} is {ans}/mins.'

print(feedback)

不确定是不是你要的东西,但姑且可以当参考吧。

(责任编辑:IT教学网)

更多

推荐CSS教程文章