π 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:
-
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 variablecar
. -
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. -
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:
- ➤ Exercise 7-1 | Rental Car
- ➤ Exercise 7-2 | Restaurant Seating
- ➤ Exercise 7-3 | Multiples of Ten
- ➤ Exercise 7-4 | Pizza Toppings
- ➤ Exercise 7-5 | Movie Tickets
- ➤ Exercise 7-6 | Three Exits
- ➤ Exercise 7-7 | Infinity
- ➤ Exercise 7-8 | Deli
- ➤ Exercise 7-9 | No Pastrami
- ➤ Exercise 7-10 | Dream Vacation
π 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
πTrending Topics
π 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
π Follow Us And Stay Updated For Daily Updates
Comments
Post a Comment