1、打印5以内不重复的三位数
count=0
for i in range(1,5):
for j in range(1,5):
if i == j:
continue
for p in range(1,5):
if i == p or j == p :
continue
count+=1
print("%d%d%d " %(i,j,p))
print("%d" %count)
2、求最小公倍数和最大公约数
while True:
a=int(input("please input first num:"))
b=int(input("please input second num:"))
Min=min(a,b)
Max=0
if Min == 0 :
print("no gong yue shu")
else:
for i in range(1,Min+1):
if a % i ==0 and b % i == 0:
Max = i
else:
continue
print("zui da gong yue shu wei:%d" %Max)
print("zui da gong bei shu wei:%d" %(a*b/Max))
3、猜数游戏
import random
i = 0
count = 0
while i < 100:
Random = random.randint(1, 100)
num = int(input("please input a num:"))
num = 10
if num > Random:
i += 1
pass
elif num < Random:
i += 1
pass
else:
count += 1
i += 1
print (count)