lesson02

python second class:
讲了循环 9*9乘法表  裴波拉数例

两个数交换,a b  a,b =b,a

        while 循环





 
 
arry = [1, 2, 3, 4]  # 有四个数字:1、2、3、4,能组成多少个互不相同且无重复数字的三位数?各是多少?
numberarry = []
for i in arry:
    for j in arry:
        for k in arry:
            if j != k and i != k and j != i:
                merge = str(i) + str(j) + str(k)
                numberarry.append(merge)
print(len(numberarry))
print(numberarry)
# 2 .求两个数的最小公倍数,最大公约数
a = int(input('输入第一个数'))
b = int(input('输入第二个数'))

count = 2
count1 = 2
if a > b:
    count = b
else:
    count = a
while True:

    if a % count == 0 and b % count == 0:
        print("以上两数的最大公约数为%s" % count)
        break
    count -= 1
    if count < 0:
        print("没有最大公约数")
        break
if a > b : count1 = a else : count1 = b while True : if count1 % a == 0 and count1 % b == 0 : print( "以上两数的最小公倍数为%s" % count1) break count1 += 1
# 求100 以类的质数


arry = []
count = 0
for i in range(2, 100):
    for j in range(2, i):
        if i % j == 0:
            count += 1
            break
    else:
        arry.append(i)

print("100以类的质数有%s 个" % len(arry))
print(arry)
 
 

from math import gcd
lcm = gcd(a, b)  # 最大公约数
lcm2 = (a * b) / lcm
print('a和b的最大公约数为:', lcm)  # 假设x和y的最大公约数是m,最小公倍数是n,则xy=mn
print('a 和b的最小公倍数:', lcm2)


猜你喜欢

转载自blog.csdn.net/hai_peng_yu/article/details/80539327