Search⌘ K
AI Features

Project: Quote Machine

Explore how to build a Python quote machine that shows random motivational, funny, or thoughtful quotes. Learn to use lists, the random module, and loops for user interaction. By the end, you'll create an interactive program with styled quotes and optional categories, enhancing your Python coding skills through a practical project.

Create a Python-powered quote machine that displays a random motivational, funny, or thoughtful quote every time you run it—or whenever the user asks for one.

This project helps you understand random selection, strings, lists, and user interaction. As a bonus, you can add flair and personality to inspire every time it runs!

Goals

You’ll aim to:

  • Store multiple quotes in a Python list.

  • Use Python’s random module to select one at random.

  • Print the quote in a fun or styled way.

  • Let the user keep generating new quotes or quit.

Project breakdown

  • Import random, define quotes in a list or dictionary, and print a welcome message.

  • Use random.choice() to show a random quote.

  • Ask the user if they want another quote; repeat or exit.

Step 1: Set up

  • Import the random module.

  • Create a list of 10–15 quotes (strings).

  • Print a welcome message.

import random

quotes = [
    "Believe you can and you're halfway there. – Theodore Roosevelt",
    "Stay hungry. Stay foolish. – Steve Jobs",
    "Be yourself; everyone else is already taken. – Oscar Wilde",
    "Do or do not. There is no try. – Yoda",
    "It always seems impossible until it's done. – Nelson Mandela",
    # ...add more quotes here!
]

print("💬 Welcome to the Quote Machine!")
Project setup

Step 2: Generate a quote

  • Use random.choice() to select and print a quote from the list.

quote = random.choice(quotes)

print("✨ Here's your quote:")
print("👉 {}".format(quote))  # or use: print(f"👉 {quote}")
Generate a random qoute from list

Step 3: User interaction

  • Use a while loop to keep generating quotes.

  • Ask the user if they want another quote.

  • Exit if they type 'n' or 'no'.

while True:
    quote = random.choice(quotes)
    print("\n👉 {}".format(quote))  # Correctly displays the quote
    
    again = input("\nWould you like another quote? (y/n): ").strip().lower()
    if again != 'y':
        print("👋 Stay inspired! Goodbye!")
        break
Add user interaction

Mini challenge

Add categories (e.g., "funny", "motivational", "tech"), and let the user choose a category before showing a quote from that group.

Hint: Use a dictionary with categories as keys and lists of quotes as values. Let the user type a category name, then use random.choice() on that list.

# Modify the code below to add categories (e.g., "funny", "motivational", "tech"), and let the user choose a category before showing a quote from that group.

import random

quotes = [
    "Believe you can and you're halfway there. – Theodore Roosevelt",
    "Stay hungry. Stay foolish. – Steve Jobs",
    "Be yourself; everyone else is already taken. – Oscar Wilde",
    "Do or do not. There is no try. – Yoda",
    "It always seems impossible until it's done. – Nelson Mandela"
]

print("💬 Welcome to the Quote Machine!")

quote = random.choice(quotes)

print("✨ Here's your quote:")
print("👉 {}".format(quote))  # or use: print(f"👉 {quote}")

while True:
    quote = random.choice(quotes)
    print("\n👉 {}".format(quote))  # Correctly displays the quote
    
    again = input("\nWould you like another quote? (y/n): ").strip().lower()
    if again != 'y':
        print("👋 Stay inspired! Goodbye!")
        break
Project setup

If you’re stuck, click the “Show Solution” button.

Project tips

  • Use emojis or borders to style quotes.

  • Store quotes in an external text file and read them with Python.

  • Add author attribution to teach string formatting.

Go further

  • Add a delay with time.sleep() before showing the next quote for drama.

  • Create a GUI version using Tkinter.

  • Build a quote API using Flask or FastAPI.

Well done! You just created your own inspiring quote machine. Customize it, add your favorite quotes, and share the positivity!