(7/10)

Importing Secret Powers (Modules) — Python typing lesson

Import modules to add powerful functions to your code.

What you'll practice

Python has secret spellbooks called modules that give you new powers! Let's import the `random` module to choose a random item.

  • `import random` brings the `random` module's powers into our program.
  • `random.choice(a_list)` picks one random item from the list you give it.

Pro Access Required

This is a premium lesson. Upgrade to Pro to unlock this interactive exercise and continue your learning journey.

🐍Python

Importing Secret Powers (Modules)

0 WPM
0% Accuracy
0:00 Time elapsed
1
2
3
4
5
6
7
8
import random↵
↵
magic_items = ['potion', 'sword', 'shield', 'gem']↵
↵
chosen_item = random.choice(magic_items)↵
↵
print('The magic chest gives you a...')↵
print(chosen_item)
0 / 167
Press This!
👇
`~
1!
2@
3#
4$
5%
6^
7&
8*
9(
0)
-_
=+
⌫
⇥
Q
W
E
R
T
Y
U
I
O
P
[{
]}
\|
⇪
A
S
D
F
G
H
J
K
L
;:
'"
↵
⇧
Z
X
C
V
B
N
M
,<
.>
/?
⇧
Thumb
Index
Middle
Ring
Pinky