• 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写asp详细讲解
  • python基础教程之面向对象的一些概念
  • python将MongoDB里的ObjectId转换为时间戳的方法
  • python循环监控远程端口的方法
  • Python的Django框架中TEMPLATES项的设置教程
  • Python根据区号生成手机号码的方法
  • Python设计模式之单例模式实例
  • Python简单删除目录下文件以及文件夹的方法
  • 零基础写python爬虫之爬虫框架Scrapy安装配置
  • Python实现查找系统盘中需要找的字符

文章分类

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

最近更新的内容

    • Python正则表达式的使用范例详解
    • 浅谈Python 对象内存占用
    • 详解Python中的正则表达式的用法
    • Python函数学习笔记
    • 数据挖掘之Apriori算法详解和Python实现代码分享
    • 全面了解Python的getattr(),setattr(),delattr(),hasattr()
    • 详解Python的Django框架中的中间件
    • python进阶教程之模块(module)介绍
    • Python交换变量
    • 利用Python获取赶集网招聘信息前篇

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

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