1、环境准备

随机生成生成计算题,那我们便需要导入random模块。

环境安装:python 3.8: 解释器、pychArm: 代码编辑器。这次的内容很简单不需要安装什么模块,直接安装完Python可以直接使用的哈~

2、主程序

import random
def add():
    a=random.randint(0,10)
    b=random.randint(0,10)
    print(f"{a}+{b}=?")
    c=input(">")
    if a+b!=int(c):
        print("wrong!")
    else:
        print("right!")

def subtract():
    j = random.randint(0, 100)
    h = random.randint(0, 100)
    print(f"{j}-{h}=?")
    s = input(">")
    if j - h != int(s):
        print("wrong!")
    else:
        print("riht!")
def multiplication():
    x=random.randint(0,100)
    y=random.randint(0,100)
    print(f"{x}*{y}=?")
    z=input(">")
    if x*y!=int(z):
        print("wrong!")
    else:
        print("riht!")
def divide():
    l = random.randint(0, 100)
    m = random.randint(1, 100)
    print(f"{l}/{m}=?")
    o = input(">")
    if l / m != float(o):
        print("wrong!")
    else:
        print("riht!")
i=1
while i<=10:
    i+=1
    add()
    multiplication()
    subtrct()
    divide()

3、效果展示

如何使用Python随机生成算数问题

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。