Exercise 3-3 Solution Python Crash Course Chapter 3: Introducing Lists

 

πŸ“˜ 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:

  1. 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.

  2. 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:


πŸ”— 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

“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