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

“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