Lecture 14 — Problem on While Loops

Overview

In this lecture we will work on problems that involve repitition.

This will involve while loops.

We will also talk about random number generation.

Many numerical simulations, including many video games, involve random events.

Python includes a module to generate numbers at random. For example,

import random

# Print three numbers randomly generated between 0 and 1.
print(random.random())
print(random.random())
print(random.random())

# Print a random integer in the range 0..5
print(random.randint(0,5))
print(random.randint(0,5))
print(random.randint(0,5))