I need help with a computer science (Python) assignment: to create a pie chart

This is a Python assignment. I already did most of the work, it's just its not able to run properly and I haven't been able to figure it out. It'd be helpful to figure out why and edit it right. 


Important* This assignment needs to run on Python IDLE.


Below is the code I completed that needs to be edited (expense_pie.py), a pdf of the specific instructions for the assignment and the txt external file (month.txt) that are the data points for the pie chart. The code I wrote is on the last page of the assignment instructions but also in a txt file. You also need to download matplotlib.pyplot to create the pie chart. Thank you for the help! 

Get Help With a similar task to - I need help with a computer science (Python) assignment: to create a pie chart

Login to view and/or buy answers.. or post an answer
Additional Instructions:

Instructions/Design Your program will process a file that contains your expenses for last month in the following six categories: ​Rent, Gas, Food, Clothing, Transportation, Misc Write a program that reads the data from an external file and uses ​matplotlib​ to plot a ​pie chart​ showing how you spend your money. Input You need an external file called month.txt with the following points: 1000 250 350 200 375 800 Output *Needs to look similar to this* Here is how to lose points on this assignment: ● Program doesn’t execute ● program does not correctly open/read from the external file ​month.txt ● graph produced is not based on data read in from file month.txt # This program displays a pie chart that expresses the money spent given data from an external file # Inputs: External file (month.txt) added to data that contains money spent # Outputs: A pie chart # Written by: Jessica Valenzuela # Modified Date: Mar 16, 2020 import matplotlib.pyplot as plt # Output that asks for external file (month.txt) filename = input('Enter the name of file : ') # Labels for pie chart labels = [ 'Rent', 'Gas', 'Food', 'Clothing', 'Transportation', 'Misc' ] # Store expenses based on labels expenses = [] strng = fptr.read() # Read the file for line in strng.split('\n'): expenses.append(int(line)) # Add color to pie chart color = ['blue', 'gold', 'green', 'red', 'purple', 'brown'] # Set the axis as equal plt.axis('equal') # Title for pie chart plt.title('Total Expenses Paid in a Month') # To plot and create the pie chart plt.figure(figsize=(5,5)) plt.pie(expenses, labels=labels, color=color, shadow=True, startangle=140) plt.show() (HERE IS THE DATA I ALREADY HAVE. Again it needs to run in Python IDLE. The problem is that it’s not running properly. I think I messed up on the store expenses based on labels part and read the file code. Please let me know what is wrong. Thank you!)

# This program displays a pie chart that expresses the money spent given data from an external file # Inputs: External file (month.txt) added to data that contains money spent # Outputs: A pie chart # Written by: Jessica Valenzuela # Modified Date: Mar 16, 2020 import matplotlib.pyplot as plt # Output that asks for external file (month.txt) filename = input('Enter the name of file : ') # Labels for pie chart labels = [ 'Rent', 'Gas', 'Food', 'Clothing', 'Transportation', 'Misc' ] # Store expenses based on labels expenses = [] strng = fptr.read() # Read the file for line in strng.split('\n'): expenses.append(int(line)) # Add color to pie chart color = ['blue', 'gold', 'green', 'red', 'purple', 'brown'] # Set the axis as equal plt.axis('equal') # Title for pie chart plt.title('Total Expenses Paid in a Month') # To plot and create the pie chart plt.figure(figsize=(5,5)) plt.pie(expenses, labels=labels, color=color, shadow=True, startangle=140) plt.show()

Related Questions

Similar orders to I need help with a computer science (Python) assignment: to create a pie chart
20
Views
0
Answers
Computer Vision - (Machine Learning, Artificial Intelligence field) assignment in python
Video processing, image processing, object detection, object tracking, background removel. It needs to be in PYTHON. Objective The goal of this project is to develop an automatic system for video analysis of footages for the game of curling. The system...
12
Views
0
Answers
Writing and understanding simple java program code
I need help writing a java program with an Eclipse IDE. Once written I need to identify, objects, lists, algorithms, set of instructions, anything that explains how the code is written, what it does, and how an end user will use it...
10
Views
0
Answers
Please assist with this program: Spiral Matrix and Recursion
You will create a C++ program to gather the clues by decoding and find the right path to the finish line. The purpose of this homework is to get students familiar with the array and recursion. 2. Input and Output a. Input file The input file contains ...
15
Views
0
Answers
Implementing PHP into webpages
The assignment is to implement PHP into a couple of webpages. I only really need about 60% of the stuff on the list done. and for the base html page, you can use whatever works, i just need something to hand to the markers so that i can have some time to w...