Python编写程序

Python编写程序,第1张

主要用到while循环和reduce 方法

from functools import reduce

sum = 0

n = 1

x = int(input())

n_value = x

while (n_value > 10(-10)):

    sum = sum + n_value

    n += 1

    # 计算第n项的值

    n_value = xn / reduce(lambda x, y: xy, range(1, n+1))

print(sum)

a=input("input:")

b=str(a)

result=""

for i in b:

result=result + i +","

print result

for line in lines:

if "曰" in line:

print line,

else:

print line, '\n'

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)"

# fatlosssplit('\n')

# print(fatloss)

find_all = refindall(r'[(]',fatloss)

exercise = []

for i in find_all:

exerciseappend(ireplace(' (','')lower())

# print(exercise)

num = refindall("\d+",fatloss)

reps_list = []

sets_list = []

for i in range(len(num)):

if i%2 == 0:

reps_listappend(int(num[i]))

else:

sets_listappend(int(num[i]))

x_list = []

for i in range(len(reps_list)):

x_listappend(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_dictget(e)

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

ans = answer(x,a)

feedback = f'The extraction of {etitle()} is {ans}/mins'

print(feedback)

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

import math

def qiugen(a,b,c):

    if a == 0:

        return “A不能为0”

    delta = mathpow(b,2) - 4ac#(pow=bb)

    if delta < 0:

        return '无实根'

    x1= (mathsqrt(delta)-b)/(2a)

    x2=-(mathsqrt(delta)+b)/(2a)

    return x1,x2

#请给出方程的a,b,c,例如2,3,4

qiugen(2,3,4)

#print(qiugen(2,3,4))

#无实根

以上就是关于Python编写程序全部的内容,包括:Python编写程序、用python编写程序、帮忙用Python写个简单的程序等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zz/10207585.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-06
下一篇 2023-05-06

发表评论

登录后才能评论

评论列表(0条)

保存