π Python Crash Course – Chapter 3: Introducing Lists – Exercise 3-3 Solution
Welcome to another solution from Python Crash Course by Eric Matthes.
π Exercise 3-3
Task:Think of your favorite mode of transportation, such as a
motorcycle or a car, and make a list that stores several examples.
Use your list
to print a series of statements about these items, such as:
“I would like to own a
Honda motorcycle .
✅ Solution Code:
fav = ["Ferrari" , "Mustang" , "Lambo"]
print(f'I will Drive a {fav[0]} one day')
print(f'I will Drive a {fav[1]} one day')
print(f'I will Drive a {fav[2]} one day')
π§ Code Explanation:
This Python code demonstrates how to create a list of favorite items and use it to generate personalized statements. Here's how it works:
-
Create a list:
The variable
fav
is assigned a list containing the names of favorite modes of transportation:["Ferrari", "Mustang", "Lambo"]
. Each item in the list represents a mode of transportation. -
Print personalized statements:
The
print()
function is used with an f-string to create and display personalized statements for each item in the list. Each item is accessed using its index (e.g.,fav[0]
,fav[1]
, etc.), and a unique statement is generated for each item.
π Output:
I will Drive a Ferrari one day
I will Drive a Mustang one day
I will Drive a Lambo one day
π Related Exercises from Chapter 3:
- ➤ Exercise 3-1 -> Names
- ➤ Exercise 3-2 -> Greetings
- ➤ Exercise 3-3 -> Your Own List
- ➤ Exercise 3-4 -> Guest List
- ➤ Exercise 3-5 -> Changing Guest List
- ➤ Exercise 3-6 -> More Guests
- ➤ Exercise 3-7 -> Shrinking Guest List
- ➤ Exercise 3-8 -> Seeing the World
- ➤ Exercise 3-9 -> Dinner Guests
- ➤ Exercise 3-10 -> Every Function
π Connect With Us:
“The only way to learn a new programming language is by writing programs in it.”
– Dennis Ritchie
π Tags: #Python #PythonCrashCourse #CodingForBeginners #LearnPython #PythonProjects #PythonTips #introducingLists
π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