云计算第三次练习

还在慢慢补充,循环还是不熟练

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值