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

 

📘 Python Crash Course – Chapter 3: Introducing Lists – Exercise 3-4 Solution

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


📝 Exercise 3-4

Task: If you could invite anyone, living or deceased, to dinner, who would you invite?
Make a list that includes at least three people you’d like to invite to dinner.
Then use your list to print a message to each person, inviting them to dinner.

✅ Solution Code:


guest = ["Iron man" , "Captain" , "Hulk"]

print(f'Hello {guest[0]} Thanks for attending My Party')
print(f'Hello {guest[1]} Thanks for attending My Party')
print(f'Hello {guest[2]} Thanks for attending My Party')

🧠 Code Explanation:

This Python code demonstrates how to create a list of guests and send personalized invitations to each of them. Here's how it works:

  1. Create a list:

    The variable guest is assigned a list containing the names of people to invite: ["Iron man", "Captain", "Hulk"]. Each name represents a guest.

  2. Print personalized invitations:

    The print() function is used with an f-string to create and display personalized invitation messages for each guest. Each name is accessed using its index (e.g., guest[0], guest[1], etc.), and a unique invitation message is generated for each guest.

🔍 Output:


Hello Iron man Thanks for attending My Party
Hello Captain Thanks for attending My Party
Hello Hulk Thanks for attending My Party

📚 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

Previous Post Next Post

Contact Form