Python Modules
💡
Exercise 39

Slot Machine 10 XP Easy

Ctrl+Enter Run Ctrl+S Save

Welcome to the final chapter: Modules! 📦

💡 Think of it like this: A module is like a toolbox. Python comes with many built-in toolboxes (modules), and you can grab specific tools from them using import.

import random # random.randint(1, 6) → random number from 1 to 6 (like a dice!) print(random.randint(1, 6)) # random.choice(['a', 'b', 'c']) → pick a random item print(random.choice(['🍎', '🍌', '🍒']))

Useful built-in modules:

  • random — Generate random numbers and choices
  • math — Math functions like sqrt(), pi
  • datetime — Work with dates and times
  • os — Interact with your computer's file system

In this exercise, we'll use the random module to build a slot machine! 🎰

📋 Instructions
Build a slot machine! 1. Import `random` 2. Create a list of symbols: `['🍒', '🍋', '🍊', '🍉', '⭐', '💎']` 3. Pick 3 random symbols 4. Print them like a slot machine 5. If all 3 match, print `JACKPOT!` Example: ``` | 🍒 | 🍋 | 🍊 | Try again! ```
Use random.choice(symbols) three times. Compare all three to check for jackpot. You've got this — take it step by step!
⚠️ Try solving it yourself first — you'll learn more!
import random

# random.randint(1, 6) → random number from 1 to 6 (like a dice!)
print(random.randint(1, 6))

# random.choice(['a', 'b', 'c']) → pick a random item
print(random.choice(['🍎', '🍌', '🍒']))
main.py
Hi! I'm Rex 👋
Output
Ready. Press ▶ Run or Ctrl+Enter.