python自动生成小学四则运算

import random

sum = input("请输入需要的题数:")
number = int(sum)
jifen = 0
i = 1
while i <= number:
    number1 = random.randint(1, 100)
    number2 = random.randint(1, 100)
    type = random.randint(1, 4)  # 1-4代表加减乘除
    if type == 1:  # 加法
        RS = number1 + number2
        print(number1, '+', number2, '=')
        rs = int(input('请输入运算结果:'))
        if rs == RS:
            jifen = int(jifen) + 10
            print("回答正确,积分加10,当前积分" + str(jifen))
        else:
            print("回答错误,正确答案是" + str(RS) + ",积分加0,当前积分" + str(jifen))
    if type == 2:  # 减法
        RS = number1 - number2
        print(number1, '-', number2, '=')
        rs = int(input('请输入运算结果:'))
        if rs == RS:
            jifen = int(jifen) + 10
            print("回答正确,积分加10,当前积分" + str(jifen))
        else:
            print("回答错误,正确答案是" + str(RS) + ",积分加0,当前积分" + str(jifen))
    if type == 3:  # 乘法
        RS = number1 * number2
        print(number1, '×', number2, '=')
        rs = int(input('请输入运算结果:'))
        if rs == RS:
            jifen = int(jifen) + 10
            print("回答正确,积分加10,当前积分" + str(jifen))
        else:
            print("回答错误,正确答案是" + str(RS) + ",积分加0,当前积分" + str(jifen))
    if type == 4:  # 除法
        RS = number1 / number2
        print(number1, '÷', number2, '=')
        rs = int(input('请输入运算结果:'))
        if rs == RS:
            jifen = int(jifen) + 10
            print("回答正确,积分加10,当前积分" + str(jifen))
        else:
            print("回答错误,正确答案是" + str(RS) + ",积分加0,当前积分" + str(jifen))
    i = i + 1
print('---------------------------------')
print('程序运行结束,您累计得分:'+str(jifen))

你可能感兴趣的:(python,算法)