Bryce H.

asked • 03/08/23

Whats wrong with my code here? python

import csv
import lasal_acreage

# import statement to import csv module
import csv


def sum_acreage(file_name):
sum = 0
with open(file_name, newline='') as csvfile:
reader = lasal_acreage .DictReader(csvfile)
for row in reader:
sum += float(row['Acreage'])

return sum


def average_acreage(file_name):
sum = 0
count = 0
with open(file_name, newline='') as csvfile:
reader = lasal_acreage .DictReader(csvfile)
for row in reader:
sum += float(row['Acreage'])
count += 1
return sum / count


def acreage_vals(file_name, area_name):
area = 0
with open(file_name, newline='') as csvfile:
reader = lasal_acreage.DictReader(csvfile)
for row in reader:
if row["Name"] == area_name:
area = row['Acreage']
return (area)


# variable to store name of csv file
# please enter the file name as required i have enter sample name
file = 'lasal_acreage.csv'
# variable to take input of user
userInput = int(input("Enter the action to be performed:1 - average, 2 - sum, 3 - values"))
# the following three if conditions check user input and respond accordingly
if userInput == 1:
output = sum_acreage(file)
print("The total acreage for all areas is:", output)
if userInput == 2:
output = average_acreage(file)
print("The average acreage for all areas is:", output)
if userInput == 3:
areaName = input("enter area name: ")
output = acreage_vals(file, areaName)
print("for ", areaName, ":", output)


2 Answers By Expert Tutors

By:

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.