Video Pending

Created by Zed A. Shaw Updated 2024-02-17 04:54:36
 

12: An Easier Way to Prompt

When you typed input() you were typing the ( and ) characters, which are parenthesis characters. For input you can also put in a prompt to show to a person so he knows what to type. Put a string that you want for the prompt inside the () so that it looks like this:

y = input("Name? ")

This prompts the user with "Name?" and puts the result into the variable y. This is how you ask someone a question and get the answer.

This means we can completely rewrite our previous exercise using just input to do all the prompting.

age = input("How old are you? ")
height = input("How tall are you? ")
weight = input("How much do you weigh? ")

print(f"So, you're {age} old, {height} tall and {weight} heavy.")
Previous Lesson Next Lesson

Register for Learn Python the Hard Way, 5th Edition (2023-2024)

Register today for the course and get the all currently available videos and lessons, plus all future modules for no extra charge.