A Python project – A random quote program (Random Quote Generator)

Lesson 4 of 15 · Python projects

In this project we will make a simple Python program that shows random quotes.

This project is good for practising working with lists, text and the random module.

In this project we will use:
  • Python lists
  • the random module
  • text data
  • printing in the terminal

How the program works

The program contains a list of well-known quotes.

Every time we run the program, Python randomly chooses one quote and shows it on the screen.


An example of the program running


Today's quote:

Programming is not about what you know, but about what you can learn.

The program code


import random

quotes = [

"Programming is not about what you know, but about what you can learn.",

"The best way to learn programming is to write code.",

"Mistakes are part of the process of learning to program.",

"Simple code is the best code."

]

quote = random.choice(quotes)

print("Today's quote:\n")
print(quote)

How this code works

  • the list quotes contains the text of the quotes
  • random.choice() chooses one element from the list
  • the program shows the quote on the screen
You can extend the program by loading the quotes from a text file or showing a new quote on every click.

Possible improvements to the project

  • read the quotes from a file
  • add the author of each quote
  • make a web version of the program
  • make a GUI application

Next project

How to make the project your own:
1) first run the given code without changes, 2) change one thing and predict what will happen, 3) add at least one feature of your own, 4) write down in a notebook what you changed and why. A work log like that is the basis of a creative programming paper.