Chapter 4.5 - More Random

4.5 - More random

Also there is a way to pick a random item out of a list. Copy the following code to Thonny :

import random my_list = ["rock", "paper", "scissors"] random_index = random.randrange(3) print(my_list[random_index])


All of the prior code generates integer numbers. If a floating point number is desired, a programmer may use the random function.

The code below generates a random number from 0 to 1

import random my_number = random.random()


and the following code creates a random number between 10 and 45

import random my_number = random.random() * 35 + 10


Can you create a code that generates a random number between 27 and 42?