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
andrey2020 [161]
3 years ago
13

Write a Python 3 program to read from a .csv file containing rates from power companies. Your program should determine the avera

ge commercial rate, and also display the information for the highest and lowest rates found.
Computers and Technology
1 answer:
aliya0001 [1]3 years ago
6 0

Answer:

In python:

file = open("rates.csv", "r")

ratecount = 0

ratesum = 0

mylist = []

rates = file.readlines()

for nums in rates:

     num = nums.rstrip('\n')

     mylist.append(int(num))

     for i in num:

           ratesum= ratesum + int(i)

           ratecount = ratecount + 1

print("Maximum Rate: "+str(max(mylist)))

print("Minimum Rate: "+str(min(mylist)))

print("Average Rate: "+str(ratesum/ratecount))

Explanation:

This opens the csv file

file = open("rates.csv", "r")

This initializes the number of rates in the file

ratecount = 0

This initializes the sum of the rates

ratesum = 0

This initializes an empty list

mylist = []

This reads the rates into lines

rates = file.readlines()

This iterates through the rates (as a string)

for nums in rates:

This removes the newline character \n in the rates

     num = nums.rstrip('\n')

This appends the rates (as an integer) to the empty list

     mylist.append(int(num))

The following counts the rates in the file and also sum them up

<em>      for i in num: </em>

<em>            ratesum= ratesum + int(i) </em>

<em>            ratecount = ratecount + 1 </em>

This prints the maximum of the rates

print("Maximum Rate: "+str(max(mylist)))

This prints the minimum of the rates

print("Minimum Rate: "+str(min(mylist)))

This calculates and prints the average rate

print("Average Rate: "+str(ratesum/ratecount))

You might be interested in
Write a function transpose(matrix) that returns the transpose of the input matrix, which is represented as a list of lists. Reca
mariarad [96]

Answer:you eat

Explanation:yea

4 0
2 years ago
Ano ang dalawang paraan sa paggawa ng abono?​
Bas_tet [7]

Answer:

im sorry i dont understand

Explanation:

5 0
3 years ago
Mario was surprised that the box that was supposed to tell him how many words he used in his document did not appear after the s
Nookie1986 [14]

Answer:

Click the Display tab

Explanation:

Choose the Word count option to make it visible, within the Display tab dropdown

7 0
3 years ago
Read 2 more answers
Repl.it Assignment 4.1.3 (Max and Min)<br> Please help me<br> I will give brainliest and a like
earnstyle [38]
-31 or 21- 50 it may also carry -31
3 0
3 years ago
When choosing field names it is best to choose names that ____?
Lelechka [254]
HTML form fields? It is best practice to use descriptive names and use a consist naming convention. My person preference is to use CamelCase, but some ppl prefer to use hyp-hens or under_scores. For example, FirstName, LastName, CellPhone, etc.
7 0
3 years ago
Read 2 more answers
Other questions:
  • How can u refer to additional information while giving a presentation
    15·1 answer
  • How can i use css/html coding to create links
    15·1 answer
  • zeroIt is a function that takes one argument and returns no value. The function stores the value 0 back into the parameter. x is
    8·1 answer
  • According to Holpp and Kelly's approaches to developing vision, the benchmarking approach is more internally focused, whereas th
    6·1 answer
  • True / False<br> The exponent in floating point is stored as a biased value.
    9·1 answer
  • Please help! would appreciate it very much!
    13·1 answer
  • Design and implement an algorithm that gets a list of k integar values N1, N2,...Nk as well as a special value SUM. Your algorit
    10·1 answer
  • Which media example would be best for mayas presentation
    7·1 answer
  • Write a list comprehension statement to generate a list of all pairs of odd posi
    7·1 answer
  • Why is my internet slow even though the speed test says it is fast
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!