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
What is the meaning of the phrase the video has gone viral
Kamila [148]

It means it's being spread really quickly all over the world.

3 0
3 years ago
Read 2 more answers
In Microsoft Word you can access the _______ command from the "Mini toolbar". A. insert citation B. save as C. underline D. word
tresset_1 [31]
Save as is the command that you would use to save anything when using microsoft
4 0
3 years ago
Read 2 more answers
Which option identifies what the computer will yield in the following scenario?
dolphi86 [110]
I think it would be the computer program will create a design with the exact dimensions
6 0
2 years ago
which of the following peripheral does not belong to a group: A) Monitor B) Printer C) Hardware D) Keyboard​
nikdorinn [45]
C hardware is the correct answer
5 0
3 years ago
Snap Me on <br>samxavier.18​
Ahat [919]

Answer:no thank you ima goody

Explanation:

7 0
2 years ago
Read 2 more answers
Other questions:
  • Generally speaking, mobile sites are good for acquiring new customers and inspiring new relationships while mobile apps are good
    6·1 answer
  • While in an interactive nslookup session, you'd use the ______ keyword to change the DNS server you're using
    5·2 answers
  • An administrator has noticed that GPO containing new update settings has not yet applied to one of the computers on the network.
    5·1 answer
  • It chapter 2 pennywise
    13·1 answer
  • How do I learn coding? Python
    5·2 answers
  • Which of these is an expansion slot type?
    5·1 answer
  • Who invented Leibnitz calculating machine ?
    12·1 answer
  • Type the correct answer in each box. Spell all words correctly, and use numerals instead of words for numbers. If necessary, use
    6·1 answer
  • What information is necessary to review in order to be considered familiar with the Safety Data Sheet (SDS) of a substance
    7·1 answer
  • This question involves the creation and use of a spinner to generate random numbers in a game. a gamespinner object represents a
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!