Python实用代码之:如何找两个数的最大公因数?

文章目录

前言

大家好,我是BoBo仔吖,欢迎来看我的文章!这节课,我教大家如何用两种方法输出最大公因数------简单版以及函数版

1.简单版

python 复制代码
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.函数封装版

python 复制代码
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,这就是两个版本的最大公因数输出方式了。

如果想了解更多,欢迎阅读我的文章!链接如下:

https://editor.csdn.net/md/?articleId=136095045#1Commonab_115

相关推荐
小田学Python3 小时前
100行Python代码,搭一个能干活的AI Agent
python·langchain·大模型·ai agent
Csvn3 小时前
🐍 Day3 : Python 容器精讲 — list、dict、set、tuple 底层实现与高级操作
后端·python
weixin-a153003083164 小时前
python-装饰器
开发语言·python
我的xiaodoujiao4 小时前
快速学习Python基础知识详细图文教程17--类型注解和断点调试
开发语言·python·学习·测试工具
每天吃饭的羊5 小时前
Chrome DevTools MCP
python
水獭比特7 小时前
localhost 不是安全边界:给 Agent Web 入口补上四层门禁
人工智能·python
Generalzy7 小时前
Whisper + VAD + TTS:一套完整的 Python 本地语音处理流水线
python·whisper·语音识别
qpsj7 小时前
让 LLM 控制 AutoCAD/ZWCAD:COM 自动化 + MCP 封装
python·llm
赟爸7 小时前
直播切片素材杂乱不好复用,易元AI要怎么处理
大数据·人工智能·python
怪奇云呼军8 小时前
从声音特征到 CRM 回流:闪电智能 Voice Agent 沟通策略自适应系统 v1 实战
android·人工智能·python·音视频·语音识别