Can you provide an example of using the input() function in Python?

QuestionsQuestions8 SkillsProYour First Python LabAug, 13 2025
0177

Certainly! Here's a simple example of using the input() function in Python to get the user's favorite color and then print a message using that input:

# Prompt the user for their favorite color
favorite_color = input("What is your favorite color? ")

# Print a message using the input
print(f"Your favorite color is {favorite_color}!")

Explanation:

  1. input("What is your favorite color? "): This line displays the prompt and waits for the user to enter their favorite color.
  2. The entered color is stored in the variable favorite_color.
  3. print(f"Your favorite color is {favorite_color}!"): This line prints a message that includes the user's input.

You can run this code in a Python environment, and it will interactively ask for the user's favorite color. Let me know if you need more examples or further assistance!

0 Comments

no data
Be the first to share your comment!