前言
大家好,我是BoBo仔吖,歡迎來看我的文章!這節(jié)課,我教大家如何用兩種方法輸出最大公因數(shù)——簡單版以及函數(shù)版
1.簡單版
a = int(input('Enter a number:'))
b = int(input('Enter a number:'))
t = a % b
while t != 0:
a = b
b = t
t = a % b
print(b)
2.函數(shù)封裝版
def Factor(a,b):
t = a % b
while t != 0:
a = b
b = t
t = a % b
return b
a = int(input('Enter a number:'))
b = int(input('Enter a number:'))
print(Factor(a,b))
OK,這就是兩個版本的最大公因數(shù)輸出方式了。
如果想了解更多,歡迎閱讀我的文章!鏈接如下:文章來源:http://www.zghlxwxcb.cn/news/detail-826096.html
https://editor.csdn.net/md/?articleId=136095045#1Commonab_115文章來源地址http://www.zghlxwxcb.cn/news/detail-826096.html
到了這里,關于Python實用代碼之:如何找兩個數(shù)的最大公因數(shù)?的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!