马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 china25qd 于 2017-6-12 08:26 编辑
先来个简单的,小明式的代码:def kf(firstfraction, secondfraction):
'九章算术之课分术\n'
'课分术曰:母互乘子,以少减多,馀为实,母相乘为法,实如法而一,即相多也。\n'
if firstfraction == secondfraction:
return "一样大,没有可比性!"
else:
talk = "%s 较大" % firstfraction if int(firstfraction.split('/')[0]) / int(firstfraction.split('/')[1]) > int(secondfraction.split('/')[0] / int(secondfraction.split('/')[1])else "%s 较大" % secondfraction
if firstfraction.split('/')[1] == secondfraction.split('/')[1]:
return talk + ",两者相差" + str(abs(firstfraction.split('/')[0] - secondfraction.split('/')[0])) + "/" + firstfraction.split('/')[1]
else:
Denominator = int(firstfraction.split('/')[1]) * int(secondfraction.split('/')[1])#母相乘
molecule = abs((int(firstfraction.split('/')[0]) * int(secondfraction.split('/')[1])) - (int(secondfraction.split('/')[0]) * int(firstfraction.split('/')[1])))#母互乘子,以少减多
return talk + ",两者相差" + str(int(molecule / gcd(Denominator, molecule))) + "/" + str(int(Denominator / gcd(Denominator, molecule)))#调用更相减损术约一下分
a = input("请输入第一个数:")
b = input("请输入第二个数:")
print("%s 和%s 两数%s " % (a, b, kf(a,b)))
更相减损术代码通道
运行结果:请输入第一个数:22/40
请输入第二个数:33/50
22/40 和33/50 两数33/50 较大,两者相差11/100
@小甲鱼 @福禄娃娃 @冬雪雪冬 |