Treino de Matematica

Script para criar lista de exercícios das 4 operações básicas da matemática. O script cria dois arquivos texto, um com a lista e outro com o gabarito. Ideal para professores e pais que acompanham os estudos dos filhos.

Script to create a exercise list to training the 4 basics mathematics operations. Good for teachers and parents.

print("input how many operations")
n = io.read("*n")
i = 1

while i < (n + 1) do
        a = math.random (99)
        b = math.random (100)
        result = a + b
        file = io.open("mathtraining2.txt","a+")
        file:write("("..i..") "..a.." + "..b.." = \n")
        file:close ()
        file = io.open("mathtraining_results2.txt","a+")
        file:write("("..i..") result = "..result.." \n")
        file:close ()
        i = i + 1
        a = math.random (99)
        b = math.random (100)
        while a < b do
            a = math.random (99)
            b = math.random (100)
        end
        result = a - b
        file = io.open("mathtraining2.txt","a+")
        file:write("("..i..") "..a.." - "..b.." = \n")
        file:close ()
        file = io.open("mathtraining_results2.txt","a+")
        file:write("("..i..") result = "..result.." \n")
        file:close ()
        i = i + 1
        a = math.random (99)
        b = math.random (100)
        result = a*b
        file = io.open("mathtraining2.txt","a+")
        file:write("("..i..") "..a.." X "..b.." = \n")
        file:close ()
        file = io.open("mathtraining_results2.txt","a+")
        file:write("("..i..") result = "..result.." \n")
        file:close ()
        i = i + 1
        a = math.random (99)
        b = math.random (37)
        rest = math.mod(a,b)
        while a < b do
            a = math.random (99)
            b = math.random (37)
            rest = math.mod(a,b)
        end
        result = (a - rest)/b
        file = io.open("mathtraining2.txt","a+")
        file:write("("..i..") "..a.." : "..b.." = \n")
        file:close ()
        file = io.open("mathtraining_results2.txt","a+")
        file:write("("..i..") result = "..result.." rest = "..rest.."\n")
        file:close ()
        i = i + 1
        a = math.random (100) -- start (+) fraction
        b = math.random (100)
        c = math.random (100)
        d = math.random (100)
        nom = (a*d) + (c*b)
        dem = (b*d)
        f = 2
        while f < (dem + 1) do -- start fraction simplification
            if  math.mod(nom,f) == 0 and  math.mod(dem,f) == 0 then
                nom = nom/f
                dem = dem/f
            else
                f = f + 1
            end -- end fraction simplification
        end
        file = io.open("mathtraining2.txt","a+")
        file:write("("..i..") "..a.."/"..b.." + "..c.."/"..d.." =\n")
        file:close ()
        file = io.open("mathtraining_results2.txt","a+")
        file:write("("..i..") result = "..nom.."/"..dem.."\n")
        file:close ()
        i = i + 1
        a = math.random (100) -- start (-) fraction
        b = math.random (100)
        c = math.random (100)
        d = math.random (100)
        while a/b < c/d do
            a = math.random (100)
            b = math.random (100)
            c = math.random (100)
            d = math.random (100)
        end
        nom = (a*d) - (c*b)
        dem = (b*d)
        f = 2
        while f < (dem + 1) do -- fraction simplification
            if  math.mod(nom,f) == 0 and  math.mod(dem,f) == 0 then
                nom = nom/f
                dem = dem/f
                else
                f = f + 1
            end
        end -- end fraction simplification
        file = io.open("mathtraining2.txt","a+")
        file:write("("..i..") "..a.."/"..b.." - "..c.."/"..d.." =\n")
        file:close ()
        file = io.open("mathtraining_results2.txt","a+")
        file:write("("..i..") result = "..nom.."/"..dem.."\n")
        file:close ()
        i = i + 1
        a = math.random (100) -- start (*) fraction
        b = math.random (100)
        c = math.random (100)
        d = math.random (100)
        nom = (a*c)
        dem = (b*d)
        f = 2
        while f < (dem + 1) do -- start fraction simplification
            if  math.mod(nom,f) == 0 and  math.mod(dem,f) == 0 then
                nom = nom/f
                dem = dem/f
            else
                f = f + 1
            end -- end fraction simplification
        end
        file = io.open("mathtraining2.txt","a+")
        file:write("("..i..") "..a.."/"..b.." X "..c.."/"..d.." =\n")
        file:close ()
        file = io.open("mathtraining_results2.txt","a+")
        file:write("("..i..") result = "..nom.."/"..dem.."\n")
        file:close ()
        i = i + 1
        a = math.random (100) -- start (:) fraction
        b = math.random (100)
        c = math.random (100)
        d = math.random (100)
        nom = (a*d)
        dem = (b*c)
        f = 2
        while f < (dem + 1) do -- start fraction simplification
            if  math.mod(nom,f) == 0 and  math.mod(dem,f) == 0 then
                nom = nom/f
                dem = dem/f
            else
                f = f + 1
            end -- end fraction simplification
        end
        file = io.open("mathtraining2.txt","a+")
        file:write("("..i..") "..a.."/"..b.." : "..c.."/"..d.." =\n")
        file:close ()
        file = io.open("mathtraining_results2.txt","a+")
        file:write("("..i..") result = "..nom.."/"..dem.."\n")
        file:close ()
        i = i + 1
    end

lista gerada pelo programa (trainning list example)
gabarito gerado pelo programa (results list example)

voltar(back)

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.