小学四则运算

个 人能力不足 搬运部分较多 以及代码 有部分未完成(以及错误)
import random

def abc():
sym=['+', '-', '×', '÷']
a = random.randint(1, 4)
# 生成随机数来对运算方式进行随机
n1 = random.randint(1, 10)

n2 = random.randint(1, 10)

result = 0
if a == 1:
result = n1 + n2
return result
elif a == 2:
result = n1 - n2
return result
  elif a == 3:
     resul = n1 * n2
     return result
elif a == 4:
while n1 % n2 != 0:
n1 = random.randint(1, 10)

n2 = random.randint(1, 10)

n1, n2 = max(n1, n2), min(n1, n2)

result = int(n1 / n2)
print(n1, sym[a], n2, '= ', end='')

return result

def test():
n = int(input('请输入需要的题数:'))

result = []

m = 0

while m <= (n - 1):
print(m + 1, end='、')

result.append(result())

print(' ')

m = m + 1

m = 0

print('对应的答案:')

while m <= (n - 1):
print(m + 1, '、', result[m])

m = m + 1

print('选择想要的模式')

print('1、进行四则运算')

print('2、制作题库')

n = int(input())

if n == 1:
while True:

result = abc()

j = input()

s = int(j)

if s == result:

print('right')

else:

print('error.,the answer is', result)

if n == 2:
test()


posted @ 2020-11-29 20:44  池鱼12156  阅读(49)  评论(0编辑  收藏  举报