student—分数加减法

x=0
a=1
f=[]
s=int(input('数1(分母):'))
j=int(input('数1(分子):'))
l=input('加减号')
d=int(input('数2(分母):'))
k=int(input('数2(分子):'))
while a<=s and a<=d:
    if s%a==0 and d%a==0:
        f.append(a)
        a=a+1   
    else:
        a=a+1
g=max(f)
n=(s//g)*(d//g)*g
if l=='+':
    n1=n//s
    n2=n//d
    j=j*n1
    k=k*n2
    x=j+k
if l=='-':
    n1=n//s
    n2=n//d
    j=j*n1
    k=k*n2
    x=j-k
print(f'{n}分之{x}')
  • 陈方旭

    Related Posts

    综合复习

    1️⃣ 认识Python Python就像和电脑说话的“魔法…

    牛马耕地

    发表回复

    您的邮箱地址不会被公开。 必填项已用 * 标注