1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Nookie1986 [14]
3 years ago
13

Create a text file that contains your expenses for last month in the following categories: • Rent • Gas • Food • Clothing • Car

payment • Misc Write a Python program that reads the data from the file and uses matplotlib to plot a pie chart showing how you spend your money

Computers and Technology
1 answer:
ololo11 [35]3 years ago
3 0

Answer:

Check the explanation

Explanation:

Code:

import matplotlib.pyplot as plt

filename = input('Enter the name of file : ')

# open file in read mode

fptr = open(filename , 'r')

# set the labels

categories = [ 'Rent', 'Gas', 'Food', 'Clothing', 'Car Payment', 'Misc' ]

# store the expenses in the order of labels

expenses = []

# read the content of file

strng = fptr.read()

# read the file line by line

for line in strng.split('\n'):

   # add the current expense to expenses

   expenses.append( int( line ) )

colors = ['gold', 'yellowgreen', 'lightcoral', 'lightskyblue', 'green', 'red']

# plot the pie chart

plt.pie(expenses, labels = categories, colors = colors, autopct='%1.1f%%', shadow=True, startangle=140)

# set the axis as equsl

plt.axis('equal')

# display the chart

plt.show()

------------------------------input.txt--------------------------

1000

235

5600

800

480

758

Kindly check the attached output image below.

You might be interested in
What is digital museum​
umka2103 [35]

Access hundreds of professional development resources for museum professionals. Museum professionals can benefit at any career stage from student to retiree. Student Membership. Industry Membership. Established Since 1906. Museum Memebership. 501(c)3 Nonprofit Org.

7 0
3 years ago
Read 2 more answers
What is the function of a slide transition in a presentation program? A. It enables you to change the presentation layouts. B. I
Lelechka [254]

The answer would be

C. It adds visual effects when you move from one slide to another.

Hope this has helped you! :)

5 0
3 years ago
Read 2 more answers
A goal should be___.
Luda [366]

Answer:

D

Explanation:

5 0
3 years ago
Read 2 more answers
my internet is really slow. i've tried rebooting my computer, erasing history, etc. how can i fix this problem?
Bingel [31]
Did u shut it down and then reset it????? Did you unplug your internet adapter????
3 0
4 years ago
Read 2 more answers
Dadadadaddaaffafafasgag
skad [1K]
Thanks for the points lol have a good day or night
7 0
3 years ago
Other questions:
  • Which of the following describes an acceptable print resolution?
    7·1 answer
  • What group actively creates technology recommendation for the web?
    8·2 answers
  • Learning about public speaking can help improve your ________________.
    15·1 answer
  • Most large organizations store data through a strategy called a(n) ________ to promote efficient and safe use of data across the
    11·1 answer
  • 1. A tachometer measures:
    8·1 answer
  • The part of the computer that contains the brain or the Central Park nursing unit is also known as
    10·1 answer
  • Interactive sites where users write about personal topic and comment to threaded discussion are called?
    10·2 answers
  • Find the root using bisection method with initials 1 and 2 for function 0.005(e^(2x))cos(x) in matlab and error 1e-10?
    8·1 answer
  • Sum of 18/7 and 13/7 is *​
    14·2 answers
  • A diagram of a ten-node network that uses ten routers
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!