Norway


In this sample , you will learn to and show the result using the print() function.

To understand this demo program, you should have the basic Python programming knowledge:

In the sample below, we are taking following two inputs from the user and store them in two different variables.

  • Total no. of random numbers to generate
  • The Upper Limit for the random numbers

To generate random integer numbers, you can use the ’s random module and one of its function known as the randint().

To generate multiple random numbers, you should call the randint() inside a For Loop.

Sample Code: Generate Random Integer Numbers

# Program to generate random integer numbers

# Import Random Module
import random

count = int(input("How many random numbers do you want to generate? "))
rmax = int(input("Enter Upper Limit for the random numbers: "))

for r in range(count):
    print(random.randint(0, rmax))

The output of the above code is as follows:

How many random numbers do you want to generate? 
Enter Upper Limit for the random numbers: 00
703
13
247
481
971
05
794
89
968
126



Source link

LEAVE A REPLY

Please enter your comment!
Please enter your name here