Computer Science
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.
Python
Python Functions
10 Likes
Answer
import random
def generate_random_number(num1, num2):
low = min(num1, num2)
high = max(num1, num2)
return random.randint(low, high)
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
for i in range(3):
random_num = generate_random_number(num1, num2)
print("Random number between", num1, "and", num2, ":", random_num)
Output
Enter the first number: 2
Enter the second number: 78
Random number between 2 and 78 : 77
Random number between 2 and 78 : 43
Random number between 2 and 78 : 52
Enter the first number: 100
Enter the second number: 599
Random number between 100 and 599 : 187
Random number between 100 and 599 : 404
Random number between 100 and 599 : 451
Answered By
2 Likes
Related Questions
Write a function to calculate volume of a box with appropriate default values for its parameters. Your function should have the following input parameters :
(a) length of box ;
(b) width of box ;
(c) height of box.
Test it by writing complete program to invoke it.
Write a program to have following functions :
(i) a function that takes a number as argument and calculates cube for it. The function does not return a value. If there is no value passed to the function in function call, the function should calculate cube of 2.
(ii) a function that takes two char arguments and returns True if both the arguments are equal otherwise False.
Test both these functions by giving appropriate function call statements.
Write a function that receives two string arguments and checks whether they are same-length strings (returns True in this case otherwise False).
Write a function namely nthRoot( ) that receives two parameters x and n and returns nth root of x i.e., x^(1/n).
The default value of n is 2.