To generate random numbers in python, you have to ask from user to enter the range (enter lower and upper limit) and again ask to enter how many random numbers he/she want to print to generate and print the desired number of random numbers as shown here in the program given below.
Following python program ask from user to enter lower and upper limit then to enter amount of numbers to generate and print the required number of random numbers:
# Python Program - Generate Random Numbers from random import randint while True: print("Enter 'x' for exit.") val1 = input("Enter lower limit: ") val2 = input("Enter upper limit: ") val3 = input("How many random numbers to print ? ") if val1 == 'x': break else: lower = int(val1) upper = int(val2) amount = int(val3) for i in range(0, amount): print(randint(lower, upper),end=" ") print("\n")
Here is the sample run of the above python program to illustrate how to generate and print random numbers:
You may also like to learn or practice the same program in other popular programming languages: