lundi 30 octobre 2017

Modulo if statement not producing expected output

I have coded a math problem prompter. And want to make sure that in the case of division. the outcome is only whole numbers and not being divided by 0. Using the following code.

while tries < problems:
    print("What is ....")
    print()
    num1 = random.randint(0,9)
    num2 = random.randint(0,9)
    operation = random.randint(1,4)
    if operation == 1:
        op = '-'
    if operation == 2:
        op = '+'
    if operation == 3:
        op = '/'
        while num2 == 0 or num1%num2 > 0:

               num1 = random.randint(0,9)
               num2 = random.randint(0,9)

However. The only problems that are generated are such that the answer is always 1. 0. or the numerator. For instance only: 4/1 5/1 6/1 or 0/5 0/6 0/6 or 3/3 2/2 1/1

Aucun commentaire:

Enregistrer un commentaire