Python | Files and folders exercise | Read in a text file containing Muppet data, and print it out

This exercise is provided to allow potential course delegates to choose the correct Wise Owl Microsoft training course, and may not be reproduced in whole or in part in any format without the prior written consent of Wise Owl.

You can learn how to do this exercise if you attend the course listed below!

Software ==> Python  (25 exercises)
Version ==> Latest version
Topic ==> Files and folders  (3 exercises)
Level ==> Average difficulty
Classroom ==> Python programming
Online ==> Python programming
Before you can do this exercise, you'll need to download and unzip this file (if you have any problems doing this, click here for help).

You need a minimum screen resolution of about 700 pixels width to see our exercises. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.

The text file in the folder above contains a list of Muppets:

Muppets

The file stores the animal type and colour of each Muppet.

 

Write a program which does the following to get the results shown below:

Step Hint
Opens the file Use with open(file_path,"r") as file_name
Reads in the lines Use read() to get the entire contents, then apply splitlines() to get a list of lines
For each line, gets the details Use split(",") to get a list of the details
Prints out the results for each You could use muppet, animal, colour = muppet_list to unpack the list into distinct variables

You don't have to use the hints - there are many ways to skin a python!

Your program should produce this output:

Final list of Muppets

The final list of Muppets your program should print.

 

When everything is working, close down your program! 

You can unzip this file to see the answers to this exercise, although please remember this is for your personal use only.
This page has 0 threads Add post