← All lessons

random: random values

Sign in · Sign up

Lesson 7.6

The random module brings randomness:

Function What it does
randint(1, 6) a whole number from 1 to 6 inclusive
choice(["a", "b"]) a random item
shuffle(list) shuffles the list in place

randint needs two arguments — from and to. shuffle returns nothing: it changes the list itself, so the result comes from the list, not from the return value.

In this check random returns pre-set values: answers says which number randint returns and which name choice returns. That's why the output is always the same. The check sets low, high, the list names and answers. Print, in order:

  1. a number from low to high — with randint;
  2. a name from names — with choice.
Hint

random.randint(a, b) gives a whole number from a to b inclusive.

random.choice(list) picks an item and returns it, so a print is needed. The bounds are low and high, the list is names.