answer.
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
Ksenya-84 [330]
2 years ago
14

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

r 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:
Whitepunk [10]2 years ago
7 0

Answer:

  1. from matplotlib import pyplot as plt
  2. with open("text.txt") as file:
  3.    data = file.readlines()
  4.    category = []
  5.    amount = []
  6.    for row in data:
  7.        values = row.split(" ")
  8.        category.append(values[0])
  9.        amount.append(float(values[1]))
  10.    
  11. figure = plt.figure()
  12. ax = figure.add_axes([0,0,1,1])
  13. ax.axis('equal')
  14. ax.pie(amount, labels = category, autopct='%1.2f%%')
  15. plt.show()

Explanation:

Firstly, we need to import matplotlib library (Line 1).

Next, open a file stream and use readlines method to read the data from the text file (Line 4). Presume the data read from the text files are as follows:

Rent 450

Gas 150

Food 500

Clothing 120

Car 600

Create two lists, category and amount (Line 5-6). Use a for loop to traverse through the read data and use split method to break each row of data into two individual items. The first item is added to category list whereas the second item is added to amount list (Line 7 - 10).

Next, create a plot figure and then add the axes (Line 12 - 13). We can use the pie method to generate a pie chart (Line 15) by setting the amount list as first argument and category list as value of labels attributes. The output pie chart can be found in the attachment.

You might be interested in
Your company wants to conduct an exploratory study to gain new insights into some product changes you are considering. Which typ
Lina20 [59]

Answer: Primary Research (Focus Group).

Explanation:

Exploratory Research is an inquiry that seeks to understand the basic causal factors of a problem. This effort can serve as the basis of more intensive research later on.

There are basically two methodologies used, which are the; Primary and Secondary methods. While the Primary method's source of information is the concerned group, the Secondary Methods obtain their information from already existing information (Primary sources), such as Interviews, Journals, etc.

In the case of the company in the question, seeking to gain insight into the changes in a product, it would be best for them to consider what some selected costumers (focus group), think about the existing products and their views on subsequent changes. This method of getting information directly from the focus group employs the primary method.

3 0
1 year ago
A file concordance tracks the unique words in a file and their frequencies. Write a program that displays a concordance for a fi
neonofarm [45]

Answer:

Python file with appropriate comments given below

Explanation:

#Take the input file name

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

#Open the input file

inputFile = open(filename,"r+")

#Define the dictionary.

list={}

#Read and split the file using for loop

for word in inputFile.read().split():

  #Check the word to be or not in file.

  if word not in list:

     list[word] = 1

  #increment by 1

  else:

     list[word] += 1

#Close the file.

inputFile.close();

#print a line

print();

#The word are sorted as per their ASCII value.

fori in sorted(list):

  #print the unique words and their

  #frequencies in alphabetical order.

  print("{0} {1} ".format(i, list[i]));

3 0
2 years ago
C# Write, compile, and test a program named PersonalInfo that displays a person’s name, birthdate, work phone number, and cell p
Soloha48 [4]

Answer:

#include <stdio.h>

#Include<iostream>

using namespace std;

//Define required function

PersonalInfo( )   {

    printf("Name   : Robert Josh\n");  

    printf("DOB    : July 14, 1975\n");  

    printf("Work Phone : 00-00000000\n");  

    printf("Cell Phone : 11-777777777\n");  

    return(0);  

 }

int main()   {

    //Call function

 PersonalInfo( );

 return 0;

 }

Explanation:

Its just a simple code to print required details when the function PersonalInfo is called.

5 0
2 years ago
A police department wants to maintain a database of up to 1800 license-plate numbers of people who receive frequent tickets so t
maksim [4K]

Answer:

c.

Explanation:

I believe that in this scenario, the best option for this data would be a hash table using open addressing with 1,800 entries. Hash tables consume more memory than lists but it makes up for it with much faster response time speeds. This is because hash tables work on a key:value system therefore, the license plate can easily be grabbed from the database extremely quickly by just plugging in the plate number. Doing so will retrieve all of the saved information from that license plate. That is why hash tables have a constant time complexity of O(1)

6 0
1 year ago
3) 5, 10, 15, 20 are items of data. Explain how these could become information and what knowledge
yKpoI14uk [10]

For example when there is research on how many people shoplift in a shopping centre per week. These numbers could show a increase in the number of shoplifters per week.

8 0
1 year ago
Other questions:
  • CAPTCHAs can be used as a form of signature to create a valid contract in e-commerce. True False
    6·2 answers
  • Any software or program that comes in many forms and is designed to disrupt the normal operation of a computer by allowing an un
    13·1 answer
  • Which of these statements regarding mobile games is true? A. They are typically played indoors. B. They have detailed environmen
    7·1 answer
  • In mathematics, the notation n! represents the factorial of the nonnegative integer n. The factorial of n is the product of all
    7·1 answer
  • Which of the following can you NOT apply for at any FLHSMV office? A. Certificate of title B. License plates C. Vehicle registra
    15·2 answers
  • Read the four detective reports and the combined affidavit and warrant for the M57 Patents case. Write a one- to two-page paper
    5·1 answer
  • During the name resolution process, which technique is used to avoid congestion when querying a server
    8·1 answer
  • Which expansion slot is used by an NVMe compliant device?
    9·1 answer
  • A credit card company receives numerous phone calls throughout the day from customers reporting fraud and billing disputes. Most
    10·1 answer
  • Exercise 3.6.9: 24 vs. "24"5 points
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!