#Project #3 Water Quality
#Project Template
def GetChoice():
#local variables
user_choice = str()
#Display menu and get choice
print()
print("Select one of the options listed below: ")
print("\tP\t==\tPrint Data")
print("\tA\t==\tGet Averages")
print("\tAZ\t==\tAverage Per Zone")
print("\tAL\t==\tAbove Levels by Zone")
print("\tBL\t==\tBelow Levels")
print("\tQ\t==\tQuit")
print()
while True:
try:
#Get choice
user_choice = input("Enter choice: ")
print()
user_choice = user_choice.upper()
#Depending on input, print items from menu
if user_choice == 'P':
PrintData()
GetChoice()
elif user_choice == 'A':
Average()
GetChoice()
elif user_choice == 'AZ':
AverageZones()
GetChoice()
elif user_choice == 'AL':
AboveLevels()
GetChoice()
elif user_choice == 'BL':
BelowLevels()
GetChoice()
elif user_choice == 'Q':
break
#Wrong input gets exception error and message error
else:
print('Invalid choice. Enter P, A, AZ, AL, BL, or Q to Quit')
except ValueError:
print('Invalid choice. Enter P, A, AZ, AL, BL, or Q to Quit')
exit
return user_choice
#enter the rest of your functions here.
def PrintData(zones):
zones = ["North 1", "North 2", "North 3", "North 4", "East 1 ", "East 2 ", "East 3 ", "East 4 ", "West 1 ", "West 2 ", "West 3 ", "West 4 ", "South 1", "South 2", "South 3", "South 4"]
lead = [10, 13, 5, 16, 17, 8, 3, 2, 6, 9, 11, 8, 4, 7, 6, 5]
copper = [0.03, 0.25, 1.4, 0.15, 0.37, 0.85, 1.5, 0.99, 0.55, 1.1, 0.97, 0.77, 0.82, 0.74, 0.96, 1.1]
#Header
print('Lead and Copper Water Study')
print()
print('Zone\t\tLead\tCopper')
print('****************************************')
#Each zone with correct lead (ppb) and copper (ppm) values
print(zones[0],'\t',lead[0],'\t',copper[0])
print(zones[1],'\t',lead[1],'\t',copper[1])
print(zones[2],'\t',lead[2],'\t',copper[2])
print(zones[3],'\t',lead[3],'\t',copper[3])
print(zones[4],'\t',lead[4],'\t',copper[4])
print(zones[5],'\t',lead[5],'\t',copper[5])
print(zones[6],'\t',lead[6],'\t',copper[6])
print(zones[7],'\t',lead[7],'\t',copper[7])
print(zones[8],'\t',lead[8],'\t',copper[8])
print(zones[9],'\t',lead[9],'\t',copper[9])
print(zones[10],'\t',lead[10],'\t',copper[10])
print(zones[11],'\t',lead[11],'\t',copper[11])
print(zones[12],'\t',lead[12],'\t',copper[12])
print(zones[13],'\t',lead[13],'\t',copper[13])
print(zones[14],'\t',lead[14],'\t',copper[14])
print(zones[15],'\t',lead[15],'\t',copper[15])
def Average():
lead = [10, 13, 5, 16, 17, 8, 3, 2, 6, 9, 11, 8, 4, 7, 6, 5]
copper = [0.03, 0.25, 1.4, 0.15, 0.37, 0.85, 1.5, 0.99, 0.55, 1.1, 0.97, 0.77, 0.82, 0.74, 0.96, 1.1]
#Average Calculation formulas
LeadAverage = sum(lead) / len(lead)
CopperAverage = sum(copper) / len(copper)
#Header
print('Average Levels of Lead and Copper')
print('*********************************')
#Format to 2 decimals
print('Lead Average:\t', format(LeadAverage, ',.2f'))
print('Copper Average:\t', format(CopperAverage, ',.2f'))
def AverageZones():
lead = [10, 13, 5, 16, 17, 8, 3, 2, 6, 9, 11, 8, 4, 7, 6, 5]
copper = [0.03, 0.25, 1.4, 0.15, 0.37, 0.85, 1.5, 0.99, 0.55, 1.1, 0.97, 0.77, 0.82, 0.74, 0.96, 1.1]
#Puts lead in their proper zones
NorthLeadZone = [lead[0], lead[1], lead[2], lead[3]]
EastLeadZone = [lead[4], lead[5], lead[6], lead[7]]
WestLeadZone = [lead[8], lead[9], lead[10], lead[11]]
SouthLeadZone = [lead[12], lead[13], lead[14], lead[15]]
#Puts copper in their proper zones
NorthCopperZone = [copper[0], copper[1], copper[2], copper[3]]
EastCopperZone = [copper[4], copper[5], copper[6], copper[7]]
WestCopperZone = [copper[8], copper[9], copper[10], copper[11]]
SouthCopperZone = [copper[12], copper[13], copper[14], copper[15]]
#Takes the lead zones to find the average in this formula
NorthLeadAverage = sum(NorthLeadZone) / len(NorthLeadZone)
EastLeadAverage = sum(EastLeadZone) / len(EastLeadZone)
WestLeadAverage = sum(WestLeadZone) / len(WestLeadZone)
SouthLeadAverage = sum(SouthLeadZone) / len(SouthLeadZone)
#Takes the copper zones to find the average in this formula
NorthCopperAverage = sum(NorthCopperZone) / len(NorthCopperZone)
EastCopperAverage = sum(EastCopperZone) / len(EastCopperZone)
WestCopperAverage = sum(WestCopperZone) / len(WestCopperZone)
SouthCopperAverage = sum(SouthCopperZone) / len(SouthCopperZone)
#Header
print('Average Values by Zone')
print('**********************')
print('Lead Averages by Zone')
print('************************')
#Lead averages put into 2 decimals
print('North\t', format(NorthLeadAverage, ',.2f'))
print('East\t', format(EastLeadAverage, ',.2f'))
print('West\t', format(WestLeadAverage, ',.2f'))
print('South\t', format(SouthLeadAverage, ',.2f'))
#Header
print('Copper Averages by Zone')
print('************************')
#Copper averages put into 2 decimals
print('North\t', format(NorthCopperAverage, ',.2f'))
print('East\t', format(EastCopperAverage, ',.2f'))
print('West\t', format(WestCopperAverage, ',.2f'))
print('South\t', format(SouthCopperAverage, ',.2f'))
def AboveLevels():
zones = ["North 1", "North 2", "North 3", "North 4", "East 1 ", "East 2 ", "East 3 ", "East 4 ", "West 1 ", "West 2 ", "West 3 ", "West 4 ", "South 1", "South 2", "South 3", "South 4"]
lead = [10, 13, 5, 16, 17, 8, 3, 2, 6, 9, 11, 8, 4, 7, 6, 5]
copper = [0.03, 0.25, 1.4, 0.15, 0.37, 0.85, 1.5, 0.99, 0.55, 1.1, 0.97, 0.77, 0.82, 0.74, 0.96, 1.1]
#Header
print('Zones Above Safe Levels')
print('***********************')
print()
#Sub-Header
print('Lead Zones Above Acceptable Levels')
print('*****************************')
#If statement formula for any lead above acceptable ppb levels
if lead[0] > 15:
print(zones[0], '\t', lead[0])
if lead[1] > 15:
print(zones[1], '\t', lead[1])
if lead[2] > 15:
print(zones[2], '\t', lead[2])
if lead[3] > 15:
print(zones[3], '\t', lead[3])
if lead[4] > 15:
print(zones[4], '\t', lead[4])
if lead[5] > 15:
print(zones[5], '\t', lead[5])
if lead[6] > 15:
print(zones[6], '\t', lead[6])
if lead[7] > 15:
print(zones[7], '\t', lead[7])
if lead[8] > 15:
print(zones[8], '\t', lead[8])
if lead[9] > 15:
print(zones[9], '\t', lead[9])
if lead[10] > 15:
print(zones[10], '\t', lead[110])
if lead[11] > 15:
print(zones[11], '\t', lead[11])
if lead[12] > 15:
print(zones[12], '\t', lead[12])
if lead[13] > 15:
print(zones[13], '\t', lead[13])
if lead[14] > 15:
print(zones[14], '\t', lead[14])
if lead[15] > 15:
print(zones[15], '\t', lead[15])
#Sub-Header
print()
print('Copper Zones Above Acceptable Levels')
print('*****************************')
#If statement formula for any copper above acceptable ppm levels
if copper[0] > 1.3:
print(zones[0], '\t', copper[0])
if copper[1] > 1.3:
print(zones[1], '\t', copper[1])
if copper[2] > 1.3:
print(zones[2], '\t', copper[2])
if copper[3] > 1.3:
print(zones[3], '\t', copper[3])
if copper[4] > 1.3:
print(zones[4], '\t', copper[4])
if copper[5] > 1.3:
print(zones[5], '\t', copper[5])
if copper[6] > 1.3:
print(zones[6], '\t', copper[6])
if copper[7] > 1.3:
print(zones[7], '\t', copper[7])
if copper[8] > 1.3:
print(zones[8], '\t', copper[8])
if copper[9] > 1.3:
print(zones[9], '\t', copper[9])
if copper[10] > 1.3:
print(zones[10], '\t', copper[10])
if copper[11] > 1.3:
print(zones[11], '\t', copper[11])
if copper[12] > 1.3:
print(zones[12], '\t', copper[12])
if copper[13] > 1.3:
print(zones[13], '\t', copper[13])
if copper[14] > 1.3:
print(zones[14], '\t', copper[14])
if copper[15] > 1.3:
print(zones[15], '\t', copper[15])
def BelowLevels():
zones = ["North 1", "North 2", "North 3", "North 4", "East 1 ", "East 2 ", "East 3 ", "East 4 ", "West 1 ", "West 2 ", "West 3 ", "West 4 ", "South 1", "South 2", "South 3", "South 4"]
lead = [10, 13, 5, 16, 17, 8, 3, 2, 6, 9, 11, 8, 4, 7, 6, 5]
copper = [0.03, 0.25, 1.4, 0.15, 0.37, 0.85, 1.5, 0.99, 0.55, 1.1, 0.97, 0.77, 0.82, 0.74, 0.96, 1.1]
#Header
print('Zones Below Safe Levels')
print('***********************')
print()
#Sub-Header
print('Lead Zones Below Acceptable Levels')
print('*****************************')
#If statement formula for any lead below acceptable ppb levels
if lead[0] < 15:
print(zones[0], '\t', lead[0])
if lead[1] < 15:
print(zones[1], '\t', lead[1])
if lead[2] < 15:
print(zones[2], '\t', lead[2])
if lead[3] < 15:
print(zones[3], '\t', lead[3])
if lead[4] < 15:
print(zones[4], '\t', lead[4])
if lead[5] < 15:
print(zones[5], '\t', lead[5])
if lead[6] < 15:
print(zones[6], '\t', lead[6])
if lead[7] < 15:
print(zones[7], '\t', lead[7])
if lead[8] < 15:
print(zones[8], '\t', lead[8])
if lead[9] < 15:
print(zones[9], '\t', lead[9])
if lead[10] < 15:
print(zones[10], '\t', lead[10])
if lead[11] < 15:
print(zones[11], '\t', lead[11])
if lead[12] < 15:
print(zones[12], '\t', lead[12])
if lead[13] < 15:
print(zones[13], '\t', lead[13])
if lead[14] < 15:
print(zones[14], '\t', lead[14])
if lead[15] < 15:
print(zones[15], '\t', lead[15])
#Sub-header
print()
print('Copper Zones Below Acceptable Levels')
print('*****************************')
#If statement formula for any copper below acceptable ppm levels
if copper[0] < 1.3:
print(zones[0], '\t', copper[0])
if copper[1] < 1.3:
print(zones[1], '\t', copper[1])
if copper[2] < 1.3:
print(zones[2], '\t', copper[2])
if copper[3] < 1.3:
print(zones[3], '\t', copper[3])
if copper[4] < 1.3:
print(zones[4], '\t', copper[4])
if copper[5] < 1.3:
print(zones[5], '\t', copper[5])
if copper[6] < 1.3:
print(zones[6], '\t', copper[6])
if copper[7] < 1.3:
print(zones[7], '\t', copper[7])
if copper[8] < 1.3:
print(zones[8], '\t', copper[8])
if copper[9] < 1.3:
print(zones[9], '\t', copper[9])
if copper[10] < 1.3:
print(zones[10], '\t', copper[10])
if copper[11] < 1.3:
print(zones[11], '\t', copper[11])
if copper[12] < 1.3:
print(zones[12], '\t', copper[12])
if copper[13] < 1.3:
print(zones[13], '\t', copper[13])
if copper[14] < 1.3:
print(zones[14], '\t', copper[14])
if copper[15] < 1.3:
print(zones[15], '\t', copper[15])
def main():
#main variables. Do not change these
GetChoice()
zones = ["North 1", "North 2", "North 3", "North 4", "East 1 ", "East 2 ", "East 3 ", "East 4 ", "West 1 ", "West 2 ", "West 3 ", "West 4 ", "South 1", "South 2", "South 3", "South 4"]
lead = [10, 13, 5, 16, 17, 8, 3, 2, 6, 9, 11, 8, 4, 7, 6, 5]
copper = [0.03, 0.25, 1.4, 0.15, 0.37, 0.85, 1.5, 0.99, 0.55, 1.1, 0.97, 0.77, 0.82, 0.74, 0.96, 1.1]
choice = str()
main()
我无法使用全局变量或拼接列表。我的问题是我不能在所有函数中重复我的列表,并且必须通过参数和参数找到一种方法来确保我的main()列表通过我的所有其他函数。非常感谢您对此的任何帮助,谢谢!