HELLO WOR|

kingwzun

园龄:3年6个月粉丝:111关注:0

7-1 sdut-分数的化简 -- Fraction的使用

做法1: 使用内置函数Fraction

from fractions import Fraction
while True:
try:
a,b=map(int,input().split("/"))
print(Fraction(a,b))
except:
break

做法2:手写gcd

知识点:gcd简单应用

def gcd(a,b):
if a%b==0:
return b
else :
return gcd(b,a%b)
while True:
try:
a,b=map(int,input().split("/"))
cnt=gcd(a,b)
if a==0:
print("0")
else:
print("{}/{}".format(a//cnt,b//cnt))
except:
break

本文作者:kingwzun

本文链接:https://www.cnblogs.com/kingwz/p/16331120.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   kingwzun  阅读(191)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起