Chapter 2
Python Program Components
Let’s look at another Python program that creates short nonsense sentences:
Listing 2.1: Mad Lib
1 # madlib.py
2 # Your Name
3
4 adjective = input("Enter an adjective: ")
5 noun = input("Enter a noun: ")
6 verb = input("Enter a verb: ")
7 adverb = input("Enter an adverb: ")
8 print("A", adjective, noun, "should never", verb, adverb)
Type this program into your Python environment, save it as madlib.py, and
run it a few times to play with it. Enter any responses you like when the
interpreter asks for them. Then consider the following aspects of both this
program and Listing 1.1.
Variables
Every program accomplishes its work ...

Get A Concise Introduction to Programming in Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.