У меня возникла ошибка арифметики c, и я не могу найти, в чем проблема. Arithmeti c error : выберите A, B или Q: A Traceback (последний вызов последним):
File «C: \ Users \ seanr \ Downloads \ Rmain. py ", строка 16, в function.pptCategory ()
File" C: \ Users \ seanr \ Downloads \ function.py ", строка 24, в pptCategory HDB = d.HDB
AttributeError: модуль 'data' не имеет атрибута 'HDB'
Вот мои коды.
**data.py**
year = [2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018]
HDB = [98139, 112520, 104543, 144415, 150158, 140286, 134257, 122876, 117947, 120168]
Private_residential = [418383, 536166, 599055, 617439, 719953, 837899, 853202, 838729, 830792, 830087]
Commercial = [630157, 896014, 1229525, 1297599, 1420893, 1452177, 1467894, 1569334, 1547935, 1635055]
Industrial = [437322, 838790, 907783, 960293, 998659, 1139602, 1265357, 1212276, 1274141, 1321801]
Others = [137739, 188774, 830623, 475979, 596153, 475327, 440070, 314253, 329847, 375977]
**function.py**
import data as d
def showmenu():
print ("="*40)
print ("A-Display the property tax collection for HDB for a selected year")
print ("B-Display the average property tax collected in the 5-year span, Display the minimum property collected in that period and the year that the minimum occurs")
print ("C-Display the three highest property tax collected and the years that they occur")
print ("D-Plot the Difference between Commercial Tax Collection and Industrial Tax Collection (for each year) vs Year, Plot the Difference Total Property Tax Collection (of all property types) vs Year.")
print ("Q- Quit the program")
print ("="*40)
def pptCategory():
year = d.year
HDB = d.HDB
yearinput = int(input("Enter the year 2009-2018: "))
idx_year = yearinput-2009
print (f"Property Tax Collection for HDB in year {year[idx_year]} is {HDB[idx_year]}.")
def avgMinppt():
prop = '''
1 : HDB
2 : Private Residential
3 : Commercial
4 : Industrial
5 : Others
'''
year_span = '''
A : 2009-2013
B : 2014-2018
'''
print(prop)
category_choice = int(input("Choose the Category : "))
print(year_span)
yrschoice = (input("Choose the Year span: "))
if category_choice == 1 and yrschoice == 'A' :
total_HDBpropertytax_2009_2013 = d.HDB[0] + d.HDB[1] + d.HDB[2] +d.HDB[3] + d.HDB[4]
average_HDBpropertytax_2009_2013 = total_HDBpropertytax_2009_2013 / 5
min_HDBpropertytax_2009_2013 = min(d.HDB[0:4])
ix = d.HDB[0:4].index(min_HDBpropertytax_2009_2013)
print (f"Average is : {average_HDBpropertytax_2009_2013}")
print (f"The minimum is : {min_HDBpropertytax_2009_2013} in year {d.year[ix]}")
if category_choice == 1 and yrschoice == 'B' :
total_HDBpropertytax_2014_2018 = d.HDB[5] + d.HDB[6] + d.HDB[7] + d.HDB[8] + d.HDB[9]
average_HDBpropertytax_2014_2018 = total_HDBpropertytax_2014_2018 / 5
min_HDBpropertytax_2014_2018 = min(d.HDB[5:9])
ix = d.HDB[5:9].index(min_HDBpropertytax_2014_2018)
print (f"Average is : {average_HDBpropertytax_2014_2018}")
print (f"The minimum is : {min_HDBpropertytax_2014_2018} in year {d.year[ix]}")
if category_choice == 2 and yrschoice == 'A' :
total_PrivateResidentialpropertytax_2009_2013 = d.Private_residential[0] + d.Private_residential[1] + d.Private_residential[2] + d.Private_residential[3] + d.Private_residential[4]
average_PrivateResidentialpropertytax_2009_2013 = total_PrivateResidentialpropertytax_2009_2013 / 5
min_PrivateResidentialpropertytax_2009_2013 = min(d.Private_residential[0:4])
ix = d.Private_residential[0:4].index(min_PrivateResidentialpropertytax_2009_2013)
print (f"Average is : {average_PrivateResidentialpropertytax_2009_2013}")
print (f"The minimum is : {min_PrivateResidentialpropertytax_2009_2013} in year {d.year[ix]}")
if category_choice == 2 and yrschoice == 'B' :
total_PrivateResidentialpropertytax_2014_2018 = d.Private_residential[5] + d.Private_residential[6] + d.Private_residential[7] + d.Private_residential[8] + d.Private_residential[9]
average_PrivateResidentialpropertytax_2014_2018 = total_PrivateResidentialpropertytax_2014_2018 / 5
min_PrivateResidentialpropertytax_2014_2018 = min(d.Private_residential[5:9])
ix = d.Private_residential[5:9].index(min_PrivateResidentialpropertytax_2014_2018)
print (f"Average is : {average_PrivateResidentialpropertytax_2014_2018}")
print (f"The minimum is : {min_PrivateResidentialpropertytax_2014_2018} in year {d.year[ix]}")
if category_choice == 3 and yrschoice == 'A' :
total_Commercialpropertytax_2009_2013 = d.Commercial[0] + d.Commercial[1] + d.Commercial[2] + d.Commercial[3] + d.Commercial[4]
average_Commercialpropertytax_2009_2013 = total_Commercialpropertytax_2009_2013 / 5
min_Commercialpropertytax_2009_2013 = min(d.Commercial[0:4])
ix = d.Commercial[0:4].index(min_Commercialpropertytax_2009_2013)
print (f"Average is : {average_Commercialpropertytax_2009_2013}")
print (f"The minimum is : {min_Commercialpropertytax_2009_2013} in year {d.year[ix]}")
if category_choice == 3 and yrschoice == 'B' :
total_Commercialpropertytax_2014_2018 = d.Commercial[5] + d.Commercial[6] + d.Commercial[7] + d.Commercial[8] + d.Commercial[9]
average_Commercialpropertytax_2014_2018 = total_Commercialpropertytax_2014_2018 / 5
min_Commercialpropertytax_2014_2018 = min(d.Commercial[5:9])
ix = d.Commercial[5:9].index(min_Commercialpropertytax_2014_2018)
print (f"Average is : {average_Commercialpropertytax_2014_2018}")
print (f"The minimum is : {min_Commercialpropertytax_2014_2018} in year {d.year[ix]}")
if category_choice == 4 and yrschoice == 'A' :
total_Industrialpropertytax_2009_2013 = d.Industrial[0] + d.Industrial[1] + d.Industrial[2] + d.Industrial[3] + d.Industrial[4]
average_Industrialpropertytax_2009_2013 = total_Industrialpropertytax_2009_2013 / 5
min_Industrialpropertytax_2009_2013 = min(d.Industrial[0:4])
ix = d.Industrial[0:4].index(min_Industrialpropertytax_2009_2013)
print (f"Average is : {average_Industrialpropertytax_2009_2013}")
print (f"The minimum is : {min_Industrialpropertytax_2009_2013} in year {d.year[ix]}")
if category_choice == 4 and yrschoice == 'B' :
total_Industrialpropertytax_2014_2018 = d.Industrial[5] + d.Industrial[6] + d.Industrial[7] + d.Industrial[8] + d.Industrial[9]
average_Industrialpropertytax_2014_2018 = total_Industrialpropertytax_2014_2018 / 5
min_Industrialpropertytax_2014_2018 = min(d.Industrial[5:9])
ix = d.Industrial[5:9].index(min_Industrialpropertytax_2014_2018)
print (f"Average is : {average_Industrialpropertytax_2014_2018}")
print (f"The minimum is : {min_Industrialpropertytax_2014_2018} in year {d.year[ix]}")
if category_choice == 5 and yrschoice == 'A' :
total_Otherspropertytax_2009_2013 = d.Others[0] + d.Others[1] + d.Others[2] + d.Others[3] + d.Others[4]
average_Otherspropertytax_2009_2013 = total_Otherspropertytax_2009_2013 / 5
min_Otherspropertytax_2009_2013 = min(d.Others[0:4])
ix = d.Others[0:4].index(min_Otherspropertytax_2009_2013)
print (f"Average is : {average_Otherspropertytax_2009_2013}")
print (f"The minimum is : {min_Otherspropertytax_2009_2013} in year {d.year[ix]}")
if category_choice == 5 and yrschoice == 'B' :
total_Otherspropertytax_2014_2018 = d.Others[5] + d.Others[6] + d.Others[7] + d.Others[8] + d.Others[9]
average_Otherspropertytax_2014_2018 = total_Otherspropertytax_2014_2018 / 5
min_Otherspropertytax_2014_2018 = min(d.Others[5:9])
ix= d.Others[5:9].index(min_Otherspropertytax_2014_2018)
print (f"Average is : {average_Otherspropertytax_2014_2018}")
print (f"The minimum is : {min_Otherspropertytax_2014_2018} in year {d.year[ix]}")
**main**
import function
loop = True
while loop:
function.showmenu()
sel = input("Please select A, B or Q: ")
if sel == "A" or sel == "a":
function.pptCategory()
elif sel == "B" or sel == 'b':
function.avgMinppt()
elif sel == "Q" or sel == 'q':
loop = False
else:
print ("Sorry invalid selection. Try again!")