A student is writing a board game in Python and needs a line that simulates one roll of a fair six-sided die. After import random, which expression returns a whole number from 1 to 6, with each of the six faces equally likely?

Choose an answer

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

A game stores six different player names as strings in the Python list players. Assume random has already been imported. Match each call with its behavior.

Match each term
A.

Returns a new list of three different names and leaves the original list unchanged.

B.

Returns one name as a string and leaves the original list unchanged.

C.

Randomly reorders the original list and returns None.

D.

Returns a new list of three names, allowing repeated names, and leaves the original list unchanged.

random.shuffle(players)

random.choice(players)

random.sample(players, k=3)

random.choices(players, k=3)

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

A game program awards a random bonus using the following line of Python, after import random:


Python
bonus = random.randrange(10, 50, 5)


Find the smallest value bonus can take, the largest value it can take, and the number of different values it can take. Give each answer as a whole number.

Your answers

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

Extra Practice