猫史档案馆


【Python作品分享】最大公因数 代码【教程贴】

用户:勇士2勇士2查看:0 回复:1 评论:0 创建时间:2021-04-18T19:34:15


【作品展示】

center_image

 

【作品介绍】

检测公因数

 

【作品源代码】

a = int(input('输入:'))
b = int(input('输入:'))
c = 0
if (a > b):
    for i in range(1, (a + 1)):
        if (a % i == 0 and b % i == 0):
            c = i
else:
    for i in range(1, (b + 1)):
        if (a % i == 0 and b % i == 0):
            c = i
print(c)
t = open('ab的公因数.txt','a')
t.write('\n')
t.write(str(a))
t.write('和')
t.write(str(b))
t.write('的最大公因数是')
t.write(str(c))

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 1下一页
心中有希望心中有希望

点赞0


评论