Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
+2 votes
in Python by (170 points)
Generate random integers between 0 and 9
In Python, How do I generate random integers between 0 to 9 ?

2 Answers

+2 votes
by (10.9k points)
edited by

@Ankita ,This is very simple ,just use the random.randint(x,y):

It returns random integers M such that randrange(x,y+1) , where x <= M <= y .

Use this code to generate random int between 0 to 9:

from random import randint

print(randint(0, 9))

Hope this answer helps.

0 votes
by (106k points)

import random


random.randint(a, b)

This returns a random integer N such that a <= N <= b.

You can use the following video tutorials to clear all your doubts:-

Related questions

Browse Categories