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)