Chapter 5a - Random
random.randrange(a, b) picks an integer from a up to but not including b.
import random
print(random.randrange(10, 20)) # 10 ... 19
π§ͺ Try it
Mini quiz β exclusive stopβ
Exclusive stop
1 / 2This call can never be which number?
random.randrange(10, 20)
Pick an answer to see if you are right.
Coin sidesβ
0 means heads, 1 means tails. Mapping that to words is just if.
Challenge: coin wordβ
Write coin(n) so it returns Heads if n is 0, otherwise Tails.
Mini quiz β randrangeβ
randrange
1 / 2This call can be which of these?
random.randrange(1, 7)
Pick an answer to see if you are right.
Exercisesβ
Activity: Team color
Write team(n) so it returns blue if n is 0, otherwise red.
(In a real program you would set n = random.randrange(0, 2).)