Learn how to interact with users through Python's input function.
Learn to use the input()
function in Python to gather user input.
The input()
function in Python is used to take input from the user. By default, the input is captured as a string. To use the input as another data type (e.g., int
or float
), you need to explicitly convert it using functions like int()
or float()
.
# Basic input
name = input("Enter your name: ")
print(f"Hello, {name}!")
# Converting input to integer
age = int(input("Enter your age: "))
print(f"In 5 years, you'll be {age + 5} years old")
Check out this Python Input Guide for more examples and detailed explanations.
Try creating programs that:
- Ask for user's name and greet them
- Get two numbers and perform calculations
- Create a simple question-answer interaction