Question
Here is my assigment and my code I did everything but NOW I need to use FUNTIONS READ before my code the feedback from my
Here is my assigment and my code I did everything but NOW I need to use FUNTIONS "READ before my code the feedback from my teacher"
THIS IS MY CODE AND WORKS BUT I NEED TO USE FUNCTIONS PLEASE HELPL ME
Python 3
myFile = input("Please enter the data file: ")
newFile = open(myFile, "r")
count_lines = 0.0
average = 0.0
highest_comercial = 0.0 #highest value
lowest_comercial = 1.0 #lowest value
value = 0.0 #store the value of commercial in float
min_val = 1.0
total = 0.0 # get the total
information = ""
low_info = ""
for line in newFile:
comm_rate = line.split(",")
count_lines = count_lines + 1
if (comm_rate[6] != "comm_rate"):
# casting from string to float
value = float(comm_rate[6])
min_val = float(comm_rate[6])
total = value + total
if (highest_comercial
highest_comercial = value
information = line
if (lowest_comercial >= min_val):
lowest_comercial = min_val
low_info = line
count_lines = count_lines - 1
average = total/count_lines
print (" The average commercial rate is: {}".format(average))
print (" The highest rate is:")
words = information.split(",")
print("{} ({}, {}) - ${} ".format(words[2],words[0],words[3],highest_comercial))
print ("The lowest rate is:")
words1 = low_info.split(",")
print("{} ({}, {}) - ${}".format(words1[2],words1[0],words1[3],lowest_comercial))
02 Prove Assignment I. Overview This assignment will give you practice using Python to read from files and process information. II. Instructions Write a Python 3 program to read from a .csv file containing rates from power companies. Your program should determine the average commercial rate, and also display the information for the highest and lowest rates found. The data file you will use is freely available from data.gov. It lists the commercial (comm rate), industrial (ind rate), and residential (res rate) rates for each zip codeStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started