100以内加减法

为了解决每天出100以内加减法和乘法题目给孩子的困扰,博主编写了一段Python代码。此代码能自动生成不超过100的加法、减法题目各20道,以及5道乘法口诀题,方便家长给孩子布置家庭作业。执行代码即可得到题目,简化了出题过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

import random

# 加法
n = 10
list1 = []
while n > 0:
    a = random.randint(0, 100)
    b = random.randint(0, 100)
    e = "{}+{}=".format(a, b)
    if a + b <= 100 and e not in list1:
        list1.append(e)
        n -= 1
        print(e)


# 减法
n = 10
list2 = []
while n > 0:
    c = random.randint(0, 100)
    d = random.randint(0, 100)
    f = "{}-{}=".format(c, d)
    if c >= d and f not in list2:
        list2.append(f)
        n -= 1
        print(f)

# 乘法
n = 5
list3 = []
while n > 0:
    c = random.randint(1, 9)
    d = random.randint(1, 9)
    f = "{}*{}=".format(c, d)
    if c >= d and f not in list3:
        list3.append(f)
        n -= 1
        print(f)

执行结果:

  

    暑假给宝宝布置的了家庭作业是每天做20道100以内加减法。每天出题都要想数字比较麻烦。就写了个代码,每天执行出结果把题发给宝宝外婆。感觉还挺好用的。另外还有5道乘法口诀题。


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值