三木社区

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 338|回复: 0
打印 上一主题 下一主题

Ex110-最小公倍数计算实验

[复制链接]

1657

主题

1684

帖子

5684

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
5684
跳转到指定楼层
楼主
发表于 2017-6-5 09:59:03 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
实验目的:
1.公倍数的求法
示例代码:
  1. def lcm(x, y):
  2.     if x > y:
  3.         greater = x
  4.     else:
  5.         greater = y
  6.     while True:
  7.         if((greater % x == 0) and (greater % y == 0)):
  8.             lcm = greater
  9.             break
  10.         greater += 1
  11.     return lcm

  12. num1 = int(input("Please enter the first number: "))
  13. num2 = int(input("Please enter the second number: "))
  14. print("Lowest common multiple of",num1,"and",num2,"is",lcm(num1,num2))
复制代码


回复

使用道具 举报

Archiver|手机版|小黑屋|三木电子社区 ( 辽ICP备11000133号-4 )

辽公网安备 21021702000620号

GMT+8, 2025-6-27 00:08 , Processed in 0.081688 second(s), 26 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表