import random
a = random.randrange(0,101)
while True:
b = int(input("请你输入一个数:"))
if b > a :
print("您猜大了")
elif b < a :
print("您猜小了")
else :
print("恭喜你,猜对了")
break
a,b = eval(input("请输入两个数:"))
if a > b :
small = b
elif b > a :
small = a
else :
print("最大公约数为:"+str(a))
exit(0)
for i in range(1,small+1) :
if a % i == 0 and b % i == 0 :
gcd = i
print("最大公约数为:"+str(gcd))
import random
import math
NOH = 0
i = 0
while i in range(0,1000001):
x = random.uniform(0,1)
y = random.uniform(0,1)
l = math.sqrt(x**2 + y**2)
i+= 1
if l < 1 :
NOH+=1
pai = (NOH * 4) / 1000000
print("π的值为:"+str(pai))
a = int(input("请输入一个数:"))
b = 2
while a != 1:
if a % b == 0:
a = a / b
print("%s "%b,end="")
else:
b = b + 1
a = 0
hang = 0
for i in range(2,1001):
for j in range(1,i+1):
if i % j == 0:
a += 1
if a == 2:
print(i,end=" ")
hang += 1
if hang % 8 == 0:
print('')
else:
a = 0
46.
pai = 0
i = int(input("请输入一个数:"))
for j in range(0,i):
pai += 1/(1+2*j)
pai *=-1
print("π的近似值为:"+str(4*pai))
结果:
a = 1
e = 0
item = 1
i = int((input("请输入i的值:")))
while item <= i:
for j in range (item):
a = a * (j + 1)
item += 1
e = 1 / a
a = 1
print("e的z近似值为:"+str(e))
a = 0
for i in range(0,1000):
for j in range(1,i):
if i % j == 0:
a += j
if a == i:
print("10000以内完全数有:",a)
a = 0
import random
time1 = 0
time2 = 0
a = ['石头','剪刀','布']
while time1 < 2 and time2 < 2 :
computer = random.choice(a)
user = input("请出石头,剪刀或者布:")
if user == computer:
print("平局!")
elif ( (user == '石头' and computer == '剪刀') or (user == '剪刀' and computer == '布') or (user == '布' and computer == '石头') ) :
time1 += 1
print("你赢了!")
else:
time2 += 1
print("电脑赢了!")
if time1 == 2:
print("你最后赢了!")
else:
print("你最后输了!")