The input() function allows your program to receive data from users:
name = input("What is your name? ")
print("Hi there, " + name)
Sample execution:
What is your name? John Doe
Hi there, John Doe
Key Points
input() always returns a string value
The text inside parentheses is the prompt
Users press Enter to submit input
Input can be stored in variables
📝 Exercise 1: Hello User (1 point)
Create a program that asks for the user's name and greets them:
What is your name? Alice
Hello Alice! Welcome to Python programming!
# Write your code here
2. Working with Variables
Storing User Input
Variables store values for later use:
name = input("What is your name? ")
print("Hi, " + name + "!")
print("Keep up the work, " + name + "!")
Variable Naming
Use descriptive names
Start with letter or underscore
Use lowercase with underscores
Avoid Python keywords
📝 Exercise 2: Personal Introduction (1 point)
Ask for name and age, then create a personalized message:
What is your name? Sarah
How old are you? 25
Sarah is 25 years old and loves Python programming!
# Write your code here
3. Combining Strings
String Concatenation
Combine strings with the + operator:
first = input("First name: ")
last = input("Last name: ")
full = first + " " + last
print("Full name: " + full)
String Methods
name.upper() - Uppercase
name.lower() - Lowercase
name.title() - Title Case
len(name) - Length
📝 Exercise 3: String Formatter (1 point)
Ask for name and hobby, create an enthusiastic message:
What is your name? Mike
What is your favorite hobby? coding
MIKE LOVES CODING!!! Let's code together!
# Write your code here
📝 Exercise 4: Multiple Inputs (1 point)
Collect first name, last name, email, and phone:
First name: John
Last name: Smith
Email: john@email.com
Phone: 555-1234
=== USER PROFILE ===
Name: John Smith
Email: john@email.com
Phone: 555-1234
# Write your code here
📝 Exercise 5: Text Analyzer (1 point)
Analyze text input with various string methods:
Enter text: Python Programming
Length: 18 characters
Uppercase: PYTHON PROGRAMMING
Lowercase: python programming
Title Case: Python Programming
# Write your code here
📝 Exercise 6: Color Preference (1 point)
Track color preference changes:
Favorite color? blue
You said: blue
Real favorite color? red
Changed from blue to red!
# Write your code here
📝 Exercise 7: Three Parts (1 point)
Ask for three parts and combine them:
Part 1: hickory
Part 2: dickory
Part 3: dock
hickory-dickory-dock!
# Write your code here
📝 Exercise 8: Story Generator (1 point)
Create a personalized story with name and year:
Name: Mary
Year: 1572
Mary is a valiant knight, born in 1572. One morning Mary woke up to an awful racket: a dragon was approaching the village. Only Mary could save the village's residents.
# Write your code here
📝 Exercise 9: Repeated Text (1 point)
Ask for a word and number, repeat the word:
Word: Python
Times: 3
PythonPythonPython
# Write your code here
📝 Exercise 10: Greeting Card (1 point)
Create a personalized greeting card:
Recipient: Sarah
Occasion: Birthday
Dear Sarah,
Happy Birthday to you!
Wishing you all the best on your special day!
With love
# Write your code here
🎉 Summary
You've completed the User Input course! You now know how to: