sa 12 cs chapter 3
7. Write a function that takes a number n and then returns a randomly generated number having exactly n digits (not starting with zero) e.g., if n is 2 then function can randomly return a number 10-99 but 07, 02 etc. are not valid two digit numbers.
# Code from random import randint def ran(n): x = int(‘9’*(n-1))+1 # first n-digit number, string is converted back to int y = int(‘9’*n) # last n-digit number return randint(x, y) print(‘Random number of digit 3 is’, ran(3)) print(‘Random number of digit 5 is’, ran(5)) # Output Random number of digit 3 is 883 Random