还在慢慢补充,循环还是不熟练
37.
import random
num = random.randrange(0,101)
print("你来辣,开始猜数字吧")
guess = int(input("我是几:"))
right = num
while True:
if guess > right:
print("过分了嗷")
guess = int(input("继续嗷:"))
elif guess < right:
print("你太卑鄙辣")
guess = int(input("继续嗷:"))
else :
print("咦,我中啦")
break
38.
num1,num2 = eval(input("请分别输入两个数:"))
k = min(num1,num2)
gcd = 1
for i in range(2,k + 1):
if num1 % i == 0 and num2 % i == 0:
gcd = i
print("%s和%s的最大公约数是%s"%(num1,num2,gcd))
39.
import random
c = 0
a = 0
while a in range(0,1000000):
x = random.random()*2-1
y = random.random()*2-1
x1 = 0
y1 = 0
a = a + 1
L = ((x - x1) * (x - x1) + (y - y1) * (y - y1)) ** 0.5
if L <= 1:
c = c + 1
else:
pass
p = (c * 4) / 1000000
print(p)
40.
a = 1
fu = 0
zheng = 0
zong = 0
shu = 0
while a != 0:
shu = shu + 1
print("按0停止")
a = int(input("请输入数字"))
a1 = a
if a1 < 0:
fu = fu + 1
if a1 > 0:
zheng = zheng + 1
zong = zong + a1
ping = zong / shu
print("正数的个数为%s"%zheng)
print("负数的个数为%s"%fu)
print("总和为%s"%zong)
print("平均数为%.3f"%ping)
41.
num = int(input("请输入一个数:"))
i = 2
while True:
if num % i == 0:
print(" ",end ="")
num /= i
else:
i += 1
if num == 1:
break