本帖最后由 paypojie 于 2023-1-3 15:19 编辑
[Python] 纯文本查看 复制代码 from tkinter import *
import random
win = Tk()
win.geometry('1010x500')
win.resizable(0,0)
win.title('100以内的数加减100以内的数')
for i in range(10):
for j in range(10):
s1 = random.randint(1,100)
s2 = random.randint(1,100)
s = random.choice("+-")
if s == '+':
s3 = s1 + s2
else:
s3 = s1 - s2
Label(win,text='%s%s%s=%s' %(s1,s,s2,s3)).grid(row=i,column=j,padx=13,pady=13)
win.mainloop()
经过坛友的提醒 写了一个更加实用的版本 如图所示 加减法的结果不会出现负数 适用于低年级的小学生
[Python] 纯文本查看 复制代码 from tkinter import *
import random
win = Tk()
win.geometry('1010x500')
win.resizable(0,0)
win.title('100以内的数加减100以内的数')
for i in range(10):
for j in range(10):
s1 = random.randint(1,100)
s2 = random.randint(1,100)
s = random.choice("+-")
if s == '+':
s3 = s1 + s2
Label(win,text='%s%s%s=%s' %(s1,s,s2,s3)).grid(row=i,column=j,padx=13,pady=13)
else:
while s1 < s2:
s1 = random.randint(1,100)
s2 = random.randint(1,100)
s3 = s1 - s2
Label(win,text='%s%s%s=%s' %(s1,s,s2,s3)).grid(row=i,column=j,padx=13,pady=13)
win.mainloop()
这段python代码已经打包为可执行的exe程序了 下载地址 https://wwzb.lanzoue.com/iIvZR0jz8lfe |