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 The whole point of this question is to get you to read the random module documentation.

Respuesta :

Answer:

import random

def ran(lower_bound, upper_bound):

   return random.randrange(lower_bound, upper_bound)

print(ran(3, 8))

Explanation:

The programming language used is python.

Modules are imported using the import keyword. In the first line the random module is imported.

A function ran is defined and it has two parameters, lower and upper bound that wll be passed to the function from random module.

The random module is a module that is used to generate random numbers, it is a very common module in programming, some of the popular functions in the module are random.randint and random.randrange. There are several other functions but these are the most common. the randint(a, b) takes two arguments and returns a random integer between the two arguments.

randrange(start, stop, step); It can take up to three arguments but has only compulsory argument that must be given for it not to generate an error and that is the stop.

when only the stop is defined, it assumes the start as zero and creates a range from 0 - stop and returns a random number within that range.

When start and stop arguments are given, it returns a number within the range of start - stop.

Start and stop must be given for there to be a step, if the step is given, it means the array containing the range of numbers will skip a step after each number.

The program makes use of the random.randrange(start, stop) and the upper and lower bounds are passed as its arguments.

Finally, the function is called and its return value is printed to the screen.

Ver imagen jehonor