用python自动出小学加减法程序

朋友们大家好,今天我给大家带来的内容是:用python做自动出题程序。

这个程序可以随机出两位数加减法的程序。

先看代码:

import time
import random


ops=['+','-']
random.shuffle(ops)
ops1=ops[0]
numbers=1
numbers1=0
while True:
    add1=random.randint(1,99)
    add2=random.randint(1,99)
    ops1=ops[0]
    eq=str(add1)+ops[0]+str(add2)
    val=eval(eq)
    if add1-add2<0:
        continue
    print('第',numbers,'题')
    time.sleep(1)
    print(add1,ops1,add2,'=')
    ask=int(input('答案是几:'))
    if ask==val:
        print('恭喜你,答对了')
        print()
        numbers+=1
        random.shuffle(ops)
    else:
        print('答错了,正确答案是',val)
        print()
        numbers+=1
        random.shuffle(ops)

来看看效果:

可以看到,程序自动出了几道两位数加减法的题目,只要输入正确的答案,程序就会告诉你你答对了。

好了,本文章的内容就到这里,感谢观看! 

猜你喜欢

转载自blog.csdn.net/hu20100913/article/details/126545150
今日推荐