矿大python学习通实验5-3和6(本人这段时间不足答疑,仅分享我成功Ac的代码,各位可以自行测试考虑以及结合ai修改来理解和掌握题目)I salute you!

# 11
def se_sum(n):
    ac = 0.0
    de = 1.0
    for i in range(1, n + 1):
        ac += i / (2 * i + 1)
        de += 2
    return ac
def digui_sum(n, term=1):
    if n == 1:
        return term / (2 * term + 1)
    else:
        return (term / (2 * term + 1)) + digui_sum(n - 1, term + 1)
n = int(input())
print("递推法:f({})={:.6f}".format(n,se_sum(n)))
print("递归法:f({})={:.6f}".format(n,digui_sum(n)))
# 12
def Pnx(n,x):
    if n==0:
        return 1
    elif n==1:
        return x
    elif n > 1: 
        return ((2*n-1)*x*Pnx(n-1,x)-(n-1)*Pnx(n-2,x))/n
n=int(input())
x=eval(input())
d = round(Pnx(n,x),6)
print("Legendre多项式的值:{}".format(d))
class BMI:
    def __init__(self, height, weight):
        self.height = height
        self.weight = weight
        self.bmi = self.weight / (self.height ** 2)
    def printBMI(self):
        print("您的BMI指数是:{:.1f}".format(self.bmi))
class ChinaBMI(BMI):
    def printBMI(self):
        super().printBMI()
        if self.bmi < 18.5:
            print("偏瘦,相关疾病发病的危险性:低")
        elif 18.5 <= self.bmi <= 23.9:
            print("正常,相关疾病发病的危险性:平均水平")
        elif 23.9 < self.bmi <= 26.9:
            print("偏胖,相关疾病发病的危险性:增加")
        elif 26.9 < self.bmi <= 29.9:
            print("肥胖,相关疾病发病的危险性:中度增加")
        else:
            print("严重肥胖, 相关疾病发病的危险性: 严重增加")
height = eval(input())
weight = eval(input())
china_bmi = ChinaBMI(height, weight)
china_bmi.printBMI()
class Vehicle():
    def __init__(self, sp, si, t, a):
        self.speed = sp
        self.size = si

        self.time = t

        self.acce = a


    def setSpeed(self):
        return self.speed
    def speedUP(self):
         return self.speed+self.time*self.acce
    def speedDown(self):
        vv=self.speed-self.time*self.acce
        if vv>=0:
            return vv
        else:
            return 0
sp = eval(input())
si = eval(input())
t = eval(input())
a = eval(input())
m=Vehicle(sp, si, t, a)
print("初速度:{} 加速度:{} 体积:{}".format(m.speed, m.acce, m.size))
print("设置的初速度为:{}".format(m.setSpeed()))
print("加速完后速度是:{}".format(m.speedUP()))
print("减速完后速度是:{}".format(m.speedDown()))
import math
class Point:
    def __init__(self, x, y):
        self.x = x
        self.y = y
    def distance(self, other):
        return math.sqrt((self.x - other.x) ** 2 + (self.y - other.y) ** 2)
class Line:
    def __init__(self, point1, point2, slope):
        self.point1 = point1
        self.point2 = point2
        self.slope = slope  # 斜率
    def relationship(self, other):
        return self.slope == other.slope
x1, y1 = eval(input())
x2, y2 = eval(input())
x3, y3 = eval(input())
x4, y4 = eval(input())
p1 = Point(x1, y1)
p2 = Point(x2, y2)
p3 = Point(x3, y3)
p4 = Point(x4, y4)
print("两点的欧式距离是{:.2f}".format(p1.distance(p2)))
if p1.x != p2.x:
	slope1 = (p2.y - p1.y)/(p2.x - p1.x)  
else:
	slope1 = None
if p3.x != p4.x:
	slope2 = (p4.y - p3.y) / (p4.x - p3.x) 
else: 
    slope2 = None
line1 = Line(p1, p2, slope1)
line2 = Line(p3, p4, slope2)
if line1.slope == line2.slope:
    print("平行")
else:
    print("相交")

  • 4
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 9
    评论
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值