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
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
Tutlance Experts offer help in a wide range of topics. Here are some of our top services:
- Math homework help
- Nursing homework help
- Statistics homework help
- Nursing coursework help
- Capstone project writing services
- Essay writers for hire
- Case study writing help
- Buy college papers online
- Buy college research papers
- College homework help
- Professional resume writing services
- Programming homework help
- Coursework writing help
- Term paper writing help
- Biology homework help
- Do my physics homework
- Dissertation data analysis help
- PhD Dissertation writing services
- Chemistry homework help
Post your project now for free and watch professional experts outbid each other in just a few minutes.