close

How do I generate a random 4 digit number and store it as a variable in python?

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How do I generate a random 4 digit number and store it as a variable in python? in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How do I generate a random 4 digit number and store it as a variable in python?

  1. How do I generate a random 4 digit number and store it as a variable in python?

    import random number = random.randint(1000,9999) print(number)

  2. generate a random 4 digit number and store it as a variable in python

    import random number = random.randint(1000,9999) print(number)

Method 1

You have a typo. It’s random.randint().

Method 2

import random
number = random.randint(1000,9999)
print(number)

Summery

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read