Introduction to Programming Using Python — Question 5

You are writing code that generates a random integer with a minimum value of 5 and a maximum value of 11.
Which two functions should you use? Each correct answer presents a complete solution. (Choose two.)

Answer options

Correct answer: B, C

Explanation

The correct answer B, random.randint(5, 11), generates a random integer between 5 and 11, inclusive. Answer C, random.randrange(5, 12, 1), also correctly produces values from 5 to 11, since the upper limit is exclusive. Answers A and D are incorrect; A goes beyond the maximum limit to 12, while D excludes 11 from the range.