Page 88 - Python Basics: A Practical Introduction to Python 3
P. 88
4.4. Interact With User Input
Here’s a sample run of the program:
Hey, what's up? Mind your own business.
You said: Mind your own business.
Once you have input from a user, you can do something with it. For
example, the following program takes user input, converts it to upper-
case with .upper(), and prints the result:
response = input("What should I shout? ")
shouted_response = response.upper()
print("Well, if you insist..." + shouted_response)
Try typing this program into IDLE’s editor window and running it.
What else can you think of to do with the input?
Review Exercises
You can nd the solutions to these exercises and many other bonus
resources online at realpython.com/python-basics/resources
1. Write a program that takes input from the user and displays that
input back.
2. Write a program that takes input from the user and displays the
input in lowercase.
3. Write a program that takes input from the user and displays the
number of characters in the input.
87