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!
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:
The file stores the animal type and colour of each Muppet.
Write a program which does the following to get the results shown below:
|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:
The final list of Muppets your program should print.
When everything is working, close down your program!