• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >python > Python实现求最大公约数及判断素数的方法

Python实现求最大公约数及判断素数的方法

作者: 字体:[增加 减小] 来源:互联网

通过本文主要向大家介绍了python求最大公约数,python 最大公约数,实现最大公约数,最大公约数,最大公约数怎么求等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

本文实例讲述了Python实现求最大公约数及判断素数的方法。分享给大家供大家参考。具体实现方法如下:

#!/usr/bin/env python 
def showMaxFactor(num): 
  count = num / 2  
  while count > 1: 
    if num % count == 0: 
      print 'largest factor of %d is %d' % (num, count) 
      break    #break跳出时会跳出下面的else语句 
    count -= 1 
  else: 
    print num, "is prime" 
for eachNum in range(10,21): 
  showMaxFactor(eachNum) 

</div>

运行结果如下:

largest factor of 10 is 5
11 is prime
largest factor of 12 is 6
13 is prime
largest factor of 14 is 7
largest factor of 15 is 5
largest factor of 16 is 8
17 is prime
largest factor of 18 is 9
19 is prime
largest factor of 20 is 10

</div>

希望本文所述对大家的Python程序设计有所帮助。

</div>

您可能想查找下面的文章:

  • 使用Python求解最大公约数的实现方法
  • Python实现求最大公约数及判断素数的方法
  • Python实现求最大公约数及判断素数的方法

相关文章

  • Python 创建子进程模块subprocess详解
  • Python的ORM框架中SQLAlchemy库的查询操作的教程
  • 利用python程序生成word和PDF文档的方法
  • Python基于scrapy采集数据时使用代理服务器的方法
  • Python字符和字符值(ASCII或Unicode码值)转换方法
  • Python3.x版本中新的字符串格式化方法
  • Python入门及进阶笔记 Python 内置函数小结
  • Python中用memcached来减少数据库查询次数的教程
  • python实现批量转换文件编码(批转换编码示例)
  • Python操作列表的常用方法分享

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • Python最基本的输入输出详解
    • tensorflow实现测试时读取任意指定的check point的网络参数
    • Python读写unicode文件的方法
    • python实现按任意键继续执行程序
    • python实现的登录和操作开心网脚本分享
    • pydev使用wxpython找不到路径的解决方法
    • 举例讲解Python中metaclass元类的创建与使用
    • 探索Python3.4中新引入的asyncio模块
    • 在ironpython中利用装饰器执行SQL操作的例子
    • Python抓取京东图书评论数据

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有