Python怎么实现随机生成算术题
作者:OpenWorld
时间:2023-05-10
浏览:2
1、环境准备随机生成生成计算题,那我们便需要导入random模块。环境安装:python3.8:解释器、pycharm:代码编辑器。这次的内容很简单不需要安装什么模块,直接安装完Python可以直接使用的哈~2、主程序importrandomdefadd():a=random.randint(0,10)b=random.randint(0,10)print(f"{a}+{b}=?")c=input(">")ifa+b!=int(c):print("wrong!")else:print("right!")d
本文目录
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、效果展示

作者最新文章
Yandex新闻入口 俄罗斯Yandex官网资讯直达
2026-11-21 10:10
QQ影音工具箱找不到转码选项怎么办
2026-11-20 17:52
漫蛙漫画弹幕怎么用?互动评论教程
2026-11-20 13:32
小橡皮一键直达入口 小橡皮AI网页版登录地址
2026-11-20 10:22
Poki免安装电脑网页版入口
2026-11-12 19:19
热门文章
更多
精品专题
更多
Mac软件
更多
WINDOWS
更多

































