147k views
0 votes
In the function below, use a function from the random module to return a random integer between the given lower_bound and upper_bound, inclusive. Don't forget to import the random module (before the function declaration).

For example, return_random_int(3, 8) should random return a number from the set: 3, 4, 5, 6, 7, 8.
length.py
def return_random_int(lower_bound, upper_bound):

1 Answer

5 votes

Answer:

import random

def return_random_int(lower_bound, upper_bound):

return random.randrange(lower_bound, upper_bound)

print(return_random_int(3, 8))

Step-by-step explanation:

Import the random module

Create a function called return_random_int takes two parameters, lower_bound and upper_bound

Return a number between lower_bound and upper_bound using random.range()

Call the function with given inputs, and print the result

User Ilya Sulimanov
by
3.0k points