Article Outline
Python example 'lesson2-Input'
lesson2-Input
Python beginners example: lesson2-Input
# This program starts by using the print(function that we learned about before.)
print("Hello, nice to meet you. I will ask you some questions.")
# In order to get some input from the user, we use the input function. The input
# function takes one argument that prompts the user for information, and returns
# a string after the user presses enter. We need to store that information in a
# variable.
birthday = input("What is your birthday? ")
# Let's use the input function again to get more information.
favoriteColor = input("What is your favorite color? ")
name = input("What is your name? ")
favoriteNumber = input("What is your favorite number? ")
# Finally we can print(the information we gathered back out to the user.)
# Remember that you have to use the + operator to concatenate two strings.
print("Hello " + name)
print("Your favorite color is " + favoriteColor)
print("You were born on " + birthday)
# ----------- Exercises Below -----------------
# 1. I asked what the users favorite number is, but I never printed the result.
# Add a print(function to line 21 to print(the favorite number back out.)
# 2. Add another input function on line 14 to ask another question, and add the
# Corresponding print(statement on line 22 to print(the information back out.)
# 3. The print(functions (lines 18 - 22) are working great, but we should end)
# our sentences with periods. Modify lines 18 - 22 to include periods.
Useful links
- Learn Python: https://pythonbasics.org
- Download Python: https://python.org