Write a function that takes an integer n and returns a random integer with exactly n digits. For instance, if n is 3, then 125 and 593 would be valid return values, but 093 would not because that is really 93, which is a two-digit number. code example

Example: Write a function that takes an integer n and returns a random integer with exactly n digits. For instance, if n is 3, then 125 and 593 would be valid return values, but 093 would not because that is really 93, which is a two-digit number.

Import random def rndnum(n):     Num = ‘’     for i in range(n):         Num = (Num + str(random.randrange(1,9))) if i == 0 else (Num + str(random.randrange(0,9)))    return int(‘’.join(Num))

Tags:

Misc Example