Write a function that receive two numbers and generate a random number from the range

 Write a function that receive two numbers and generate a random number from the range


This program is easy to understand .

Let us understand first understand the question .In this question here we have to first take any two numbers whether by user or static.

Now you have to get output any random number in between the given two numbers.


Let us follow the steps given below:

1.Define any function using def keyword and make function.

2.Now you can take input the two numbers inside the function or the main part of the function.

here i will take inside the function.

3.import random module to use randint() function.

4.And use print() function to print randomly any number using randint() function.

5.now come outside the function i.e main part ,then call your function.


Testcases1:

Input:

2

9

Output:

6


Testcases2:

Input:

6

98655467

Output:

1065




def num():

    N1=int(input("Enter a first number:"))

    N2=int(input("Enter second number:"))

    import random 

    print(random.randint(N1,N2))

num()



No comments:

Powered by Blogger.