Python3 code: Create a simple text file called mycandy The first line of the file will be Candy Name, Candy Calories, Total Fat Grams Next, add five lines to the file by hand using your favorite five candy bars information. Each line's data will be separated by commas. Create a class called Candy which keeps track of the three pieces of information Read in the file line by line and create a Candy class instance for each candy bar you have, and add that new instance to a list. Once you have the list created, loop through the list and print the candy bar info out to the console Add a line of code to append one more candy bar’s information to your mycandy file. Show what your new text file looks like after the append
Python3 code:
Create a simple text file called mycandy
The first line of the file will be
Candy Name, Candy Calories, Total Fat Grams
Next, add five lines to the file by hand using your favorite five candy bars information. Each line's data will be separated by commas.
Create a class called Candy which keeps track of the three pieces of information
Read in the file line by line and create a Candy class instance for each candy bar you have, and add that new instance to a list.
Once you have the list created, loop through the list and print the candy bar info out to the console
Add a line of code to append one more candy bar’s information to your mycandy file. Show what your new text file looks like after the append
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 7 images