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.)
BD, is not the correct answer, it is actually BC, I've checked it on an online python IDE, random.randrange(5, 12, 1) will show numbers from 5 to 11 because it's last parameter excludes 1 number from 12, so 11 will be the maximum number shown
It's a tricky question but BC are correct because randint is inclusive and randrange is not inclusive. So when using randint you would need (5,11), which is the equivalent of randrange(5,12)
random.randrange(start, stop[, step])
random.randint(a, b)
Return a random integer N such that a <= N <= b. Alias for randrange(a, b+1).
-----------
random.randint(5,11) chooses between 5,6,...10,11
random.randrange(5,12) chooses between 5,6,...10,11 ie LAST NUMBER is EXCLUDED
so BC marked is indeed correct
BC is correct.
Here is my sample code to prove it.
from random import randint, randrange
resultint = []
resultrange = []
for i in range (50):
resultint.append(randint(5,11))
resultrange.append(randrange(5,12,1))
print(resultint)
print (resultrange)
This section is not available anymore. Please use the main Exam Page.98-381 Exam Questions
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
atxsu
Highly Voted 5 years, 2 months agoshtingdcknipples
Most Recent 4 years, 1 month agosagacious_smith
4 years, 2 months agoFuzzyDunlop
4 years, 10 months agogargaditya
4 years, 6 months agoJAKJR
4 years, 10 months agoFerdex
4 years, 11 months agoKrish3197
5 years agoTshego1995
5 years, 2 months agodale
5 years, 2 months ago