Open In App

How to generate a random phone number using Python?

In this article, we will learn how to generate a random phone number using Python. In general, Indian phone numbers are of 10 digits and start with 9, 8, 7, or 6.

Approach:



Examples:

The generated random phone numbers would looklike:
9980231467
8726189362

Implementation:






# import module
import random as r
  
ph_no = []
  
# the first number should be in the range of 6 to 9
ph_no.append(r.randint(6, 9))
  
# the for loop is used to append the other 9 numbers.
# the other 9 numbers can be in the range of 0 to 9.
for i in range(1, 10):
    ph_no.append(r.randint(0, 9))
  
# printing the number
for i in ph_no:
    print(i, end="")

Output:

8349603502
Article Tags :