GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

No menu could be recovered. Follow the blue links in the page.

This view

  • Original page
  • New address

GeezerVison is showing inventwithpython.com — Gullible

(Close Ad) Other books by Al Sweigart, free online or available for purchase:
BUY THIS BOOK: No Starch Press (free ebook) | Amazon | Barnes and Noble | Powell's | Bookshop.org | Goodreads | Kobo | Thriftbooks
SUPPORT THE AUTHOR: Patreon or Donate Directly
Prev: Guess the Number | Next: Hacking Minigame

In this short and simple program, you can learn the secret and subtle art of keeping a gullible person busy for hours. I won’t spoil the punch line here. Copy the code and run it for yourself. This project is great for beginners, whether you’re smart or . . . not so smart.

The Program in Action

When you run gullible.py, the output will look like this:

Gullible, by Al Sweigart [email protected]
Do you want to know how to keep a gullible person busy for hours? Y/N
> y
Do you want to know how to keep a gullible person busy for hours? Y/N
> y
Do you want to know how to keep a gullible person busy for hours? Y/N
> yes
Do you want to know how to keep a gullible person busy for hours? Y/N
> YES
Do you want to know how to keep a gullible person busy for hours? Y/N
> TELL ME HOW TO KEEP A GULLIBLE PERSON BUSY FOR HOURS
"TELL ME HOW TO KEEP A GULLIBLE PERSON BUSY FOR HOURS" is not a valid yes/no response.
Do you want to know how to keep a gullible person busy for hours? Y/N
> y
Do you want to know how to keep a gullible person busy for hours? Y/N
> y
Do you want to know how to keep a gullible person busy for hours? Y/N
> n
Thank you. Have a nice day!

How It Works

To be more user friendly, your programs should attempt to interpret a range of possible inputs from the user. For example, this program asks the user a yes/no question, but it would be simpler for the player to simply enter “y” or “n” instead of enter the full word. The program can also understand the player’s intent if their caps lock key is activated, because it calls the lower() string method on the string the player entered. This way, 'y', 'yes', 'Y', 'Yes', and 'YES', are all interpreted the same by the program. The same goes for a negative response from the player.

Download Source Code

 1. """Gullible, by Al Sweigart [email protected]
 2. How to keep a gullible person busy for hours. (This is a joke program.)
 3. View this code at https://nostarch.com/big-book-small-python-projects
 4. Tags: tiny, beginner, humor"""
 5.
 6. print('Gullible, by Al Sweigart [email protected]')
 7.
 8. while True:  # Main program loop.
 9.     print('Do you want to know how to keep a gullible person busy for
        hours? Y/N')
10.     response = input('> ')  # Get the user's response.
11.     if response.lower() == 'no' or response.lower() == 'n':
12.         break  # If "no", break out of this loop.
13.     if response.lower() == 'yes' or response.lower() == 'y':
14.         continue  # If "yes", continue to the start of this loop.
15.     print('"{}" is not a valid yes/no response.'.format(response))
16.
17. print('Thank you. Have a nice day!')

Exploring the Program

Try to find the answers to the following questions. Experiment with some modifications to the code and rerun the program to see what effect the changes have.

  1. What happens if you change response.lower() == 'no' on line 11 to response.lower() != 'no'?
  2. What happens if you change while True: on line 8 to while False:?
Prev: Guess the Number | Next: Hacking Minigame
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.