Exercise 8-9 Solution Python Crash Course Chapter 8 : Functions

 

📘 Python Crash Course – Chapter 8: Functions – Exercise 8-9 Solution

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


📝 Exercise 8-9

Task:
Make a list of magician’s names . Pass the list to a function called show_magicians(), which prints the name of each magician in the list

✅ Solution Code:


# List of magician's names
magicians = ["David Copperfield", "Harry Houdini", "Penn & Teller", "Dynamo", "Criss Angel"]

def show_magicians(magicians_list):
    for names in magicians_list:
        print(names)

# Call the function to show the names of the magicians
show_magicians(magicians)


🧠 Code Explanation:

  1. Create a list of magicians:

    The variable magicians is assigned a list containing the names of famous magicians, such as ["David Copperfield", "Harry Houdini", "Penn & Teller", "Dynamo", "Criss Angel"].

  2. Define the function:

    The function show_magicians(magicians_list) is defined to accept one parameter:

    • magicians_list: Represents the list of magician names passed to the function.
  3. Iterate through the list:

    Inside the function, a for loop is used to iterate through each element in the magicians_list. The variable names takes on the value of each magician's name during each iteration.

  4. Display each name:

    For each iteration, the name of the magician is displayed. This ensures that all names in the list are processed and shown.

  5. Call the function:

    The function show_magicians() is called with the magicians list as an argument. This passes the list of magician names to the function for processing.

🔍 Output:


David Copperfield
Harry Houdini
Penn & Teller
Dynamo
Criss Angel

📚 Related Exercises from Chapter 8:


🔗 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

📌 Tags: #Python #PythonCrashCourse #CodingForBeginners #LearnPython #PythonProjects #PythonTips

Previous Post Next Post

Contact Form