Been trying to make a small program that shoots out random math problems to solve. I can get it to shoot the problems but I don't know how to unite the random problem with the answer in it's class. Really new to coding if it isn't incredibly obvious...
Heres my whole code:
while Peli != "end":
ratkaisu = input(random.choice(Lists.Laskut).problem)
if ratkaisu == Lists.Laskut.answer:
print("oikein")
elif ratkaisu != Lists.Laskut.answer:
print("väärin")
elif ratkaisu == "loppu":
Peli == "end"
Heres the lists used:
Kysymys = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Vastaus = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
Laskut = [
Algebra(Kysymys[0], Vastaus[0]),
Algebra(Kysymys[1], Vastaus[1]),
Algebra(Kysymys[2], Vastaus[2]),
Algebra(Kysymys[3], Vastaus[3]),
Algebra(Kysymys[4], Vastaus[4]),
Algebra(Kysymys[5], Vastaus[5]),
Algebra(Kysymys[6], Vastaus[6]),
Algebra(Kysymys[7], Vastaus[7]),
Algebra(Kysymys[8], Vastaus[8]),
Algebra(Kysymys[9], Vastaus[9]),]
And heres the class template "Algebra":
class Algebra:
def __init__(self, problem, answer):
self.problem = problem
self.answer = answer
Aucun commentaire:
Enregistrer un commentaire