Friday , September 20 2024

Look at the code below: import random # # Insert lines of code here. # print(a, b, c) Which lines of code would you insert so that it is possible for the program to output the following result:

Questions BankCategory: Python Essentials 2Look at the code below: import random # # Insert lines of code here. # print(a, b, c) Which lines of code would you insert so that it is possible for the program to output the following result:
Look at the code below:

import random
 
#
# Insert lines of code here.
#
 
print(a, b, c)

Which lines of code would you insert so that it is possible for the program to output the following result:
[box type="shadow" align="" class="" width=""]Output 6 82 0[/box]

A:
[box type="shadow" align="" class="" width=""]a = random.randrange(10, 100, 3)
b = random.randint(0, 100)
c = random.choice((0, 100, 3))[/box]

B:
[box type="shadow" align="" class="" width=""]a = random.choice((0, 100, 3))
b = random.randrange(10, 100, 3)
c = random.randint(0, 100)[/box]

C:
[box type="shadow" align="" class="" width=""]a = random.randint(0, 100)
b = random.randrange(10, 100, 3)
c = random.choice((0, 100, 3))[/box]

D:
[box type="shadow" align="" class="" width=""]a = random.randint(0, 100)
b = random.choice((0, 100, 3))
c = random.randrange(10, 100, 3)[/box]

  • D
  • C
  • B
  • A

Explanation: Let’s analyze the randint, randrange, and choice functions:

  • The randint(0, 100) function returns any random integer from 0 to 100 inclusive, so it’s possible that a 6 is returned.
  • The randrange(10, 100, 3) function returns any random integer from 10 to 100 with step three, so it’s possible that 82 is returned.
  • The choice(0, 100, 3) function returns (“chooses”) one element from the sequence of elements 0, 100, 3, so it’s possible that a 0 is returned.

More Questions: Python Essentials 2 (PE2) Course Final Test