Home › Python with Chai › Lesson 13

Modules: the lucky chai

Python with Chai, lesson 13 of 20. A short Hinglish video, simple English notes and code you can run, free.

Open the interactive lesson with Run button

The idea

A module is a ready-made toolbox of code. You don't write it yourself, you import it.

random comes with Python. random.choice(list) picks one item from a list, a different one each run.

random.randint(1, 10) gives a whole number from 1 to 10, and both ends are included.

The code

import random

chai = ["Masala", "Adrak", "Elaichi"]
print("Aaj ki lucky chai:", random.choice(chai))

num = random.randint(1, 10)
print("Lucky number:", num)

Output:

Aaj ki lucky chai: Elaichi
Lucky number: 7
(run it again: you get new answers)

Try it yourself

Remember

Don't build every tool yourself: import it.

← Files: read the bill back · f-strings: a neat bill →

All lessons: Python with Chai