mercredi 3 novembre 2021

Generate input options

I'm making a small math program for practice purposes.

The user is supposed to enter, how many digits the two summands should have.

I did this as shown below:

import random
digits = input("How many digits should the numbers have? ")
if digits == "1":
    while True:
        num1 = random.randint(0,10)
        num2 = random.randint(0,10)
        solution = num1 + num2
        print(str(num1) + " + " + str(num2) + " = ? ")
        question = input()

How can I automate the process, so that I don't have to manually add the digits as they increase?

Sorry for my basic question, but I hope someone can help me with this.




Aucun commentaire:

Enregistrer un commentaire