Q. Write a function that takes a number n and then returns a randomly generated number having exactly n digits (not starting with zero)
eg ., if n is 2 then function can randomly return a number 10-99 but 07, 02 etc. are not valid two digit numbers.
You can understand by Watching video :-
Answer:-
import random def ran( x ) : a = 10 ** (x - 1 ) b= 10 ** (x ) print( random.randint ( a , b ) ) n = int(input("Enter number of digit : ")) ran(n)
Output :-
Enter number of digit : 2
72
>>>
Enter number of digit : 9
638330587
>>>
Enter number of digit : 5
75450
>>>
Enter number of digit : 10
5498667849
>>>
Enter number of digit : 100
4655969082985716754399543003519602906342699471049675327533099576946492019622835421434523706415649864
>>>
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )