Q. Write a function that receives two numbers and generates a random number from that range Using this function, the main program should be able to print three numbers randomly.


You can understand by Watching video :-



Answer :-

import random

def ran(a , b) :
    print( random . randint(a , b ) )
   
first = int(input("Enter  a number = "))
second = int(input("Enter second number = "))

ran(first , second )
ran(first , second )
ran(first , second )

Output :-

Enter Frist number = 2
Enter Second number = 9
3
9
4

>>> 

Enter Frist number = 100
Enter Second number = 1566
1010
1015
651

>>> 

Enter Frist number = 56416
Enter Second number = 56166351
38740824
36091125
52147407

>>>


12 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

  1. thanks for your answer

    ReplyDelete
  2. U could have used:

    for i in range(3):
    ran(first , second )

    instead of:

    ran(first , second )
    ran(first , second )
    ran(first , second )

    ReplyDelete
  3. Nice teaching 👍

    ReplyDelete
  4. can u do it without random module?

    ReplyDelete
  5. Can it be done without random module?

    ReplyDelete
  6. By user defined function can we do this question ,that is not using randint function

    ReplyDelete

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post