|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#随机生成十道十以内的加减乘除并给出答案
import random
for i in range(11):
a = random.randint(1,10)
b = random.randint(1,10)
c = ['/','*','-','+']
f = random.randint(0,3)
print("%d%s%d="%(a,c[f],b))
g = int(input())
if f == 0:
if g == a//b:
print("%d%s%d=%d √"%(a,'//',b,a//b))
else:
print("%d%s%d=%d × 正确答案为 %d"%(a,'/',b,g,a/b))
if f ==1:
if g == a*b:
print("%d%s%d=%d √"%(a,'*',b,a*b))
else:
print("%d%s%d=%d × 正确答案为 %d"%(a,'*',b,g,a*b))
if f ==2:
if g == a-b:
print("%d%s%d=%d √"%(a,'-',b,a-b))
else:
print("%d%s%d=%d × 正确答案为 %d"%(a,'-',b,g,a-b))
if f == 3:
if g == a+b:
print("%d%s%d=%d √"%(a,'+',b,a+b))
else:
print("%d%s%d=%d × 正确答案为 %d"%(a,'+',b,g,a+b))
import random
d = []
for i in range(11):
a = random.randint(1,10)
b = random.randint(1,10)
c = ['/','*','-','+']
f = random.randint(0,3)
print("%d%s%d="%(a,c[f],b))
g = int(input())
if f == 0:
if g == a // b:
d . append("%d%s%d=%d √"%(a,'//',b,a//b))
else:
d . append("%d%s%d=%d × 正确答案为 %d"%(a,'/',b,g,a/b))
if f ==1:
if g == a*b:
d . append("%d%s%d=%d √"%(a,'*',b,a*b))
else:
d . append("%d%s%d=%d × 正确答案为 %d"%(a,'*',b,g,a*b))
if f ==2:
if g == a-b:
d . append("%d%s%d=%d √"%(a,'-',b,a-b))
else:
d . append("%d%s%d=%d × 正确答案为 %d"%(a,'-',b,g,a-b))
if f == 3:
if g == a+b:
d . append("%d%s%d=%d √"%(a,'+',b,a+b))
else:
d . append("%d%s%d=%d × 正确答案为 %d"%(a,'+',b,g,a+b))
for x in range(len(d)):
print('第%2d题 : %s' % (x + 1 , d[x]))
|
|