samedi 29 décembre 2018

Can't make this random number generator to work properly

I'm trying to make a random number generator and return the random generated number, but this code returns all the numbers before the random number. How can I return only the last string printed?

import random

from_num = int(input('Generate a random number:\nFrom:'))
to_num = int(input('To:'))

for num in range(random.randrange(from_num,to_num+1)):
    if True:
        print(f'Random number: {num}')
    else:
        print('You did not entered valid min/max numbers')

Output for from_num = 0 and to_num = 20 by exemple, instead of '11' can return any number between these two given.

Random number: 0
Random number: 1
Random number: 2
Random number: 3
Random number: 4
Random number: 5
Random number: 6
Random number: 7
Random number: 8
Random number: 9
Random number: 10
Random number: 11




Aucun commentaire:

Enregistrer un commentaire