0% found this document useful (0 votes)
15 views7 pages

Communities Program 07222024

Uploaded by

zel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views7 pages

Communities Program 07222024

Uploaded by

zel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 7

Communities = []

StatsPopulation = []
StatsLiveBirths = []
StatsDeaths = []
StatsInfant = []
StatsMaternal = []
StatsFetal = []
StatsFemale = []

def mainMenuDisplay():
print()
print(" WELCOME TO VITAL STATISTICS INFORMATION SYSTEM ")
print("---------------------------------------------------------")
print("PRESS FROM THE FOLLOWING OPTION:")
print("Press 1. TO DISPLAY THE DEFINITION OF HEALTH INDICES.")
print("Press 2. TO ADD HEALTH INDICES INFORMATION.")
print("Press 3. TO DELETE HEALTH INDICES INFORMATION.")
print("Press 4. TO UPDATE HEALTH INDICES INFORMATION.")
print("Press 5. TO DISPLAY HEALTH INDICES INFORMATION.")
print("Press 6. TO DISPLAY VITAL HEALTH INDICATORS.")
print("Press 7. TO EXIT SYSTEM.")

def mainMenu(choiceMenu):
mainMenuDisplay()
while True:
try:
choiceMenu = int(input("Enter your option (1-7): "))
if 0 <= choiceMenu <= 7:
mainMenuEngine(choiceMenu)
else:
print("ERROR: Invalid input. Please enter a value between 1 and 7.")
except ValueError:
print("ERROR: Invalid input. Please enter a number.")

#Option 1, display the definition of health indices


def display_definitions():
definitions = {
"Total Population": "The total number of people in that area at a given
time.",
"Total Live Births": "The complete expulsion or extraction from its mother
of a product of conception, irrespective of the duration of the pregnancy, which
after such separation, breathes or shows any other evidence of life, such as
beating of the heart, pulsation of the umbilical cord, or definite movement of
voluntary muscles, whether or not the umbilical cord has been cut or the placenta
is attached; each product of such birth is considered liveborn.",
"Total Deaths": "Is the permanent disappearance of all evidence of life at
any time after live birth has taken place (postnatal cessation of vital functions
without capability of resuscitation).",
"Infant Deaths": "The death of an infant under one year of age.",
"Maternal Deaths": "The death of a woman while pregnant or within 42 days
of termination of pregnancy, irrespective of the duration and the site of the
pregnancy, from any cause related to or aggravated by the pregnancy or its
management, but not from accidental or incidental causes.",
"Fetal Deaths": "The death is indicated by the fact that after such
separation the fetus does not breathe or show any other evidence of life, such as
beating of the heart, pulsation of the umbilical cord, or definite movement of
voluntary muscles.",
"Female Population (15-49 years old)": "The total number of female ages 15-
49 years old in that area at a given time."
}
print("\n--------------------------------------------------------")
print("Health Indices Definitions")
print("--------------------------------------------------------\n")
for key, value in definitions.items():
print(f"{key}: {value}\n")
print("--------------------------------------------------------")

def get_valid_number(prompt):
while True:
try:
return int(input(prompt))
except ValueError:
print("Invalid input. Please enter a valid number.")

#Option 2, adds vital statistics information


def healthIndices_add():
print("--------------------------------------------------------")
print("ADDING HEALTH INDICES INFORMATION \n")
communityInput = (input("Enter the name of the community: ")).capitalize()
if communityInput in Communities:
print("ERROR: It already exists.")
else:
populationInput = get_valid_number("Enter Total Population: ")
livebirthsInput = get_valid_number("Enter Total Live Births: ")
deathsInput = get_valid_number("Enter Total Deaths: ")
infantdeathsInput = get_valid_number("Enter Infant Deaths: ")
maternaldeathsInput = get_valid_number("Enter Maternal Deaths: ")
fetaldeathInput = get_valid_number("Enter Fetal Deaths: ")
femalepopInput = get_valid_number("Enter Female Population (15-49 years
old): ")

Communities.append(communityInput)
StatsPopulation.append(populationInput)
StatsLiveBirths.append(livebirthsInput)
StatsDeaths.append(deathsInput)
StatsInfant.append(infantdeathsInput)
StatsMaternal.append(maternaldeathsInput)
StatsFetal.append(fetaldeathInput)
StatsFemale.append(femalepopInput)

while True:
while True:
more = input("\nDo you want to add more communities? (yes/no):
").strip().lower()
if more in ("yes", "no"):
break
else:
print("Please only answer yes/no")

if more == 'yes':
healthIndices_add()
else:
break
break

#Option 3, delete the health indices information


def healthindices_delete ():
if len(Communities) == 0:
print('\nThe directory is empty.')
return

x=1
print("--------------------------------------------------------")
for Comm in Communities:
print(x, '.', Comm)
x+=1
print(x,'. Remove All.')
print(x+1, '. Cancel')
#remove_info = int(input('Enter a number to delete: '))

while True:
try:
remove_info = get_valid_number("Enter a number to delete: ")
if 0 < remove_info < len(Communities)+2:
if remove_info == x:
clearALL()
return
if remove_info == x + 1:
return
remove = Communities[remove_info -1]
Communities.pop(remove_info-1)
StatsPopulation.pop(remove_info - 1)
StatsLiveBirths.pop(remove_info - 1)
StatsDeaths.pop(remove_info - 1)
StatsInfant.pop(remove_info - 1)
StatsMaternal.pop(remove_info - 1)
StatsFetal.pop(remove_info - 1)
StatsFemale.pop(remove_info - 1)
print(remove, 'has been deleted from the directory.')
return
else:
print('ERROR: Invalid input. Please enter a value between 1 and ',
len(Communities)+2)
except ValueError:
print('ERROR: Invalid input. Please enter a number.')

#if invalidChecker(remove_info, len(Communities) + 2):


# print('ERROR: Invalid Input.')
# return

def clearALL():
Communities.clear()
StatsPopulation.clear()
StatsLiveBirths.clear()
StatsDeaths.clear()
StatsInfant.clear()
StatsMaternal.clear()
StatsFetal.clear()
StatsFemale.clear()
print('\nHealth Indices Information have been deleted in the directory.')

#Option 4, update the health indices information


def health_indices_Update ():
if len(Communities) == 0:
print('\nThe directory is empty.')
return
x=1
print("--------------------------------------------------------")
for Comm in Communities:
print(x, '.', Comm)
x+=1
print(x,'. Cancel.')
update_healthindices = int(input('Enter a number to update: '))
if update_healthindices == x:
return
if invalidChecker(update_healthindices, len(Communities)):
print('ERROR: Invalid input.')
return
update_HealthIndices(update_healthindices)

def update_HealthIndices(update_healthindices):
print("--------------------------------------------------------")
update_healthindices2 = get_valid_number('PICK INFORMATION TO UPDATE: \n 1.
Total Population \n 2. Total Live Births \n 3. Total Deaths \n 4. Infant Deaths \n
5. Maternal Deaths \n 6. Fetal Deaths \n 7. Female Population \n 8. Cancel:\n ')
if update_healthindices2 == 1:
newPopulation = get_valid_number("Enter new Total Population: ")
StatsPopulation[update_healthindices - 1] = newPopulation
print("Total Population of ", Communities[update_healthindices-1], "is
updated.")
return
elif update_healthindices2 == 2:
newLiveBirths = get_valid_number ("Enter new Total Live Births: ")
StatsLiveBirths [update_healthindices - 1] = newLiveBirths
print("Total Live Births of ", Communities[update_healthindices-1], "is
updated.")
return
elif update_healthindices2 == 3:
newDeaths = get_valid_number("Enter new Total Death: ")
StatsDeaths [update_healthindices - 1] = newDeaths
print("Total Death of ", Communities[update_healthindices-1], "is
updated.")
return
elif update_healthindices2 == 4:
newInfant = get_valid_number("Enter new Infant Deaths: ")
StatsInfant [update_healthindices - 1] = newInfant
print("Infant Deaths of ", Communities[update_healthindices-1], "is
updated.")
return
elif update_healthindices2 == 5:
newMaternal = get_valid_number("Enter new Maternal Deaths: ")
StatsMaternal [update_healthindices - 1] = newMaternal
print("Maternal Deaths of ", Communities[update_healthindices-1], "is
updated.")
return
elif update_healthindices2 == 6:
newFetal = get_valid_number("Enter new Fetal Death: ")
StatsFetal [update_healthindices - 1] = newFetal
print("Fetal Death of ", Communities[update_healthindices-1], "is
updated.")
return
elif update_healthindices2 == 7:
newFemale = get_valid_number("Enter new Female Population (15 - 49 years
old): ")
StatsFemale [update_healthindices - 1] = newFemale
print("Female Population (15 - 49 years old) of ",
Communities[update_healthindices-1], "is updated.")
return
elif update_healthindices2 == 8:
return

#Option 5, show the list of the health indices information


def HIinfo_list ():
if len(Communities) == 0:
print('\nThe directory is empty.')
return
print("--------------------------------------------------------")
Comm_index = 0
print(' HEALTH INDICES INFORMATION TABLE ')
# Prepare data in a dictionary format for easy table printing
data = {
Comm: {
"Population": StatsPopulation[index],
"Live Births": StatsLiveBirths[index],
"Deaths": StatsDeaths[index],
"Infant Deaths": StatsInfant[index],
"Maternal Deaths": StatsMaternal[index],
"Fetal Deaths": StatsFetal[index],
"Female Pop. (15-49)": StatsFemale[index]
} for index, Comm in enumerate(Communities)
}

# Extract keys and community names


communities = list(data.keys())
indices_keys = list(data[communities[0]].keys())

# Calculate maximum lengths for proper alignment


max_key_len = max(len(key) for key in indices_keys) + 2
max_val_len = max(len(str(val)) for community in communities for val in
data[community].values()) + 2

# Print headers
print("Health Indices".ljust(max_key_len), end="")
for community in communities:
print(community.ljust(max_val_len), end="")
print()

# Print each health index


for key in indices_keys:
print(key.ljust(max_key_len), end="")
for community in communities:
print(str(data[community][key]).ljust(max_val_len), end="")
print()

#Option 6,display the vital health INDICATORS


def calculate_vital_health_indicators():
if len(Communities) == 0:
print('\nThe directory is empty.')
return
print("--------------------------------------------------------")
Comm_index = 0
print(' VITAL HEALTH INDICATORS INFORMATION ')
# Prepare data in a dictionary format for easy table printing
data = {
Comm: {
"Crude Birth Rate": '{:.2f}'.format((StatsLiveBirths[index] /
StatsPopulation[index]) * 1000),
"Crude Death Rate": '{:.2f}'.format((StatsDeaths[index] /
StatsPopulation[index]) * 1000),
"Fetal Death Ratio": '{:.2f}'.format((StatsFetal[index] /
StatsLiveBirths[index]) * 1000),
"Fetal Death Rate": '{:.2f}'.format((StatsFetal[index] /
(StatsLiveBirths[index] + StatsFetal[index])) * 1000),
"Infant Mortality": '{:.2f}'.format((StatsInfant[index] /
StatsLiveBirths[index]) * 1000),
"Maternal Mortality Rate": '{:.2f}'.format((StatsMaternal[index] /
StatsFemale[index]) * 1000),
"Maternal Mortality Ratio": '{:.2f}'.format((StatsMaternal[index] /
StatsLiveBirths[index]) * 1000)
} for index, Comm in enumerate(Communities)
}

# Extract keys and community names


communities = list(data.keys())
indices_keys = list(data[communities[0]].keys())

# Calculate maximum lengths for proper alignment


max_key_len = max(len(key) for key in indices_keys) + 2
max_val_len = max(len(str(val)) for community in communities for val in
data[community].values()) + 2

# Print headers
print("Health Indices".ljust(max_key_len), end="")
for community in communities:
print(community.ljust(max_val_len), end="")
print()

# Print each health index


for key in indices_keys:
print(key.ljust(max_key_len), end="")
for community in communities:
print(str(data[community][key]).ljust(max_val_len), end="")
print()

def invalidChecker(userInput, maximum):


if userInput <= 0 or userInput > maximum:
return True
return False

#option 7, exit
def exitProgram():
print("--------------------------------------------------------")
print("YOU HAVE SUCCESSFULLY EXITED THE SYSTEM.")
exit()

def mainMenuEngine(choice):
if choice == 1:
display_definitions()
mainMenu(0)
elif choice == 2:
healthIndices_add()
mainMenu(0)
elif choice == 3:
healthindices_delete()
mainMenu(0)
elif choice == 4:
health_indices_Update()
mainMenu(0)
elif choice == 5:
HIinfo_list()
mainMenu(0)
elif choice == 6:
calculate_vital_health_indicators()
mainMenu(0)
elif choice == 7:
exitProgram()
else:
return

mainMenu(0)

You might also like