π 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:
-
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. -
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:
- ➤ 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