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

“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