Lesson 2: Your First Python Program
Topics Covered:
- Using
input()
to ask the user questions - Combining
print()
andinput()
to create interactive programs
Asking the User for Input
The input()
function allows your program to ask the user for information. Example:
name = input("What is your name? ")
print("Hello, " + name + "!")
Activity: Create an Interactive Greeting
Ask the user for their favorite color and use print()
to respond:
color = input("What is your favorite color? ")
print("Nice! " + color + " is a great color!")
Challenge Task
- Ask the user for their name, favorite animal, and favorite food.
- Then use
print()
to create a fun sentence like:
name = input("What is your name? ")
animal = input("What is your favorite animal? ")
food = input("What is your favorite food? ")
print(name + " loves eating " + food + " with a " + animal + "!")
Try It Yourself!
Open Python or your online editor and run the examples above. Modify them to make your own silly story.