A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://inventwithpython.com/bigbookpython/project32.html below:

Gullible

#32
Gullible

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.

 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:?

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4