Python Program to print Random Numbers

In this post, let’s write a simple Python program to print random numbers. To print random numbers it’s very simple in Python as it has a random package available in the Python core itself.

Here is the simple program: 

# Import random package

import random

# Let's print random numbers between 0 and 100
rand_num = random.randint(0,100)
print (rand_num)

The above program will print random numbers between 0 and 100.

Let’s write the same program getting the inputs from the user: 

# Import random package

import random

# Get the input from user
print ("Enter the start range: ")
num1 = input()
print ("Enter the end range: ")
num2 = input()

# Let's print random numbers between 0 and 100
rand_num = random.randint(num1,num2)
print ("The random number is:")
print (rand_num)

Example Output of the above program is: 

Enter the start range: 
1
Enter the end range: 
1000
The random number is:
733

I hope this post would have helped you to learn basic Python programming.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top