20以内加减随机试卷

 

问题:20以内加减法,相加不能超过20,相减不能为负

函数公式解决

第一个数: =RANDBETWEEN(0,20)

加减符号:=IF(RANDBETWEEN(0,1),"+","-")

第二个数:=IF(C1="-",RANDBETWEEN(0,B1),RANDBETWEEN(0,20-B1))

 

=====================2022-4-12补充=====================

后来有同学问如何实现20以内类似8+7-2这种,写了段代码:

Sub Sample()
Dim MyRow As Long, MyCol As Long, i As Long, j As Long
For MyRow = 1 To 20
    Cells(MyRow, 1) = Int(Rnd * 21)
    j = Cells(MyRow, 1)
    For MyCol = 2 To 4 Step 2
        i = Int(Rnd * 2)
        If i Then
            Cells(MyRow, MyCol) = "+"
            Cells(MyRow, MyCol + 1) = Int(Rnd() * (20 - j))
        Else
            Cells(MyRow, MyCol) = "-"
            Cells(MyRow, MyCol + 1) = Int(Rnd() * j)
        End If
        j = Evaluate(Cells(MyRow, 1) & Cells(MyRow, 2) & Cells(MyRow, 3))
    Next
    Cells(MyRow, 6) = Evaluate(j & Cells(MyRow, 4) & Cells(MyRow, 5))
Next
End Sub

  

posted @ 2022-02-25 17:06  熬肥妖  阅读(236)  评论(0编辑  收藏  举报