WAP to make function that take number n and then return randomly generated number having exactly digits''' #In the first line code we will define a function and write single parameter i.e n #Then we use random module then we take variable min and max #3 in given qurstion if n=2,then we have to find range between 10 -99 it means 10**(2-1) to 10**2 i.e 10 - 100 but given 10-99 . #4 so we will use randrange() we gives starting number to ending-1. def rand(n): import random min=10**(n-1) max=10**n return random.randrange(min,max) n=int(input("Enter a value of n:")) print("Two digits number is",rand(n))
WAP to make function that take number n and then return randomly generated number having exactly digits'''
WAP to make function that take number n and then return randomly generated number having exactly digits'''
#In the first line code we will define a function and write single parameter i.e n
#Then we use random module then we take variable min and max
#3 in given qurstion if n=2,then we have to find range between 10 -99 it means 10**(2-1) to 10**2 i.e 10 - 100 but given 10-99 .
#4 so we will use randrange() we gives starting number to ending-1.
def rand(n):
import random
min=10**(n-1)
max=10**n
return random.randrange(min,max)
n=int(input("Enter a value of n:"))
print("Two digits number is",rand(n))
digits'''
#In the first line code we will define a function and write single parameter i.e n
#Then we use random module then we take variable min and max
#3 in given qurstion if n=2,then we have to find range between 10 -99 it means 10**(2-1) to 10**2 i.e 10 - 100 but given 10-99 .
#4 so we will use randrange() we gives starting number to ending-1.
def rand(n):
import random
min=10**(n-1)
max=10**n
return random.randrange(min,max)
n=int(input("Enter a value of n:"))
print("Two digits number is",rand(n))
No comments: