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
The word blog is made from what two terms?
mafiozo [28]
• web + log = blog •
3 0
3 years ago
Earning wise scope of web and mobile app development
lubasha [3.4K]

Answer:

Mobile are build in a specific platform such as Android, iOS ect and they use application such as apple store and have access to the system such as GPS and the camera. Mobile apps live and run on mobiles as on they are their own thing controlled by a developer on the other end

Explanation:

3 0
3 years ago
How many feet do you have to stop away from a school bus
mr_godi [17]
You are required by law to stop twenty feet away from a school bus when driving.
7 0
3 years ago
Write a program that receives a series of numbers from the user and allows the user to press the enter key to indicate that he o
Dmitriy789 [7]

Answer:

The solution code is written in Python 3

  1. count = 0
  2. sum = 0
  3. num = input("Enter a number: ")
  4. while(num != ''):
  5.    sum += float(num)
  6.    count += 1
  7.    num = input("Enter a number: ")
  8. print("Sum : " + str(sum))
  9. print("Average: " + str(sum / count))

Explanation:

Firstly, we declare two variables count and sum to hold the number of input number and the total of the input number, respectively (Line 1-2)

Next, we prompt user to input the first number (Line 4). While the num is not ' ' (This means it is not "Enter" key), accumulate the num to sum variable and increment count by one (Line 6-8) and then prompt the user to input the next number (Line 9).

At the end, display the sum and average using print function (Line 11 -12).

5 0
3 years ago
What controls a computer's basic operations?
S_A_V [24]
 Basic Computer Operations. Input: Information and programs are entered into the computer through Input devices such as the keyboard, disks, or through other computers via network connections or modems connected to the Internet. The input device also retrieves information off disks.
3 0
3 years ago
Other questions:
  • A job posting is the best way to find out what _____ are required for a position.A.aptitudes B.hard skills C.soft skills D.dress
    10·2 answers
  • The _________ element enables developers to embed a self-contained web page within another html document.
    12·1 answer
  • Gina's teacher has sent her a Word document that contains the names of all the students who are participating in the
    11·2 answers
  • How should you dress for a phone interview
    12·2 answers
  • What languages do most of the students at Miami High School speak?
    6·2 answers
  • A dns query failure is referred to a higher level domain name server under what condition
    7·2 answers
  • Write a program named split_me.py that accepts a string in the format Age.FirstName and returns the value FirstName is Age years
    14·1 answer
  • I NEED THIS ASAP PLS
    12·1 answer
  • what is the name of the program that enables the device and operating system to communicate with each other?
    7·1 answer
  • marion is an iot developer working for a large organization. why does his supervisor want him to stay informed about the network
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!