Exercise 7-1 Solution Python Crash Course Chapter 7 : User Input And While Loops

 

📘 Python Crash Course – Chapter 7: User Input And while loops – Exercise 7-1 Solution

Welcome to another solution from Python Crash Course by Eric Matthes.


📝 Exercise 7-1

Task:
Write a program that asks the user what kind of rental car they would like . Print a message about that car, such as “Let me see if I can find you a Subaru .

✅ Solution Code:


car = input("What kind of rental car would you like? ")
print(f"Let me see if I can find you a {car.title()}.")

🧠 Code Explanation:

  1. Prompt the user for input:

    The input() function is used to ask the user what kind of rental car they would like. The user's response is stored in the variable car.

  2. Format the input:

    The title() method is applied to the user's input to capitalize the first letter of each word. This ensures that the car name is displayed in a proper format.

  3. Display a personalized message:

    The program uses the user's input to construct a message indicating that it will try to find the requested car.

This code demonstrates how to use user input to make a program interactive and how to format the input for better readability in the output.

🔍 Output:


What kind of rental car would you like? BMW
Let me see if I can find you a Bmw.

📚 Related Exercises from Chapter 7:


🔗 Connect With Us:

“In the world of code, Python is the language of simplicity, where logic meets creativity, and every line brings us closer to our goals.”
— Only Python

📌 Tags: #Python #PythonCrashCourse #CodingForBeginners #LearnPython #PythonProjects #PythonTips

Previous Post Next Post

Contact Form