lundi 12 septembre 2016

(Python) Generating Numbers then Printing them on One Line

I have an assignment that requires me to print 10 random sums, then get the user to enter their answers. I know how to randomly generate numbers, but I need to print the whole sum out, without giving the answer, but with the string I am using it adds them automatically.

This is my code below:

for i in range(10):
        number1 = (random.randint(0,20))
        number2 = (random.randint(0,20))
        print (number1 + number2)
    answer = input("Enter your answer: ")

If someone could help me out I would appreciate it, I believe the line

    print (number1 + number2)

is the problem, as it is adding them when I just want the random numbers printed in the sum.

Thanks in advance,

Flynn.




Aucun commentaire:

Enregistrer un commentaire