In: Computer Science
In Python, write a program that allows the user to enter a number between 1-5 and returns the vitamins benefits based on what the user entered. The program should:
You can use the following facts:
1- Vitamin A protects eyes from night blindness and age-related decline
2- Vitamin B6 promotes brain health and reduces Alzheimer's risk
3- Vitamin B12 may improve health by decreasing homo-cysteine
4- Vitamin C protects your health from cardiovascular issues, cancer and strokes
5- Vitamin D reduces the risk of diabetes
All code must be contained in a function ( except calling main() )
printWelcome(): function that prints welcome message
getValidInput(): takes user input until valid and returns the valid input to main()
main() – allows user to continue enter numbers until entering zero “0” to quit, uses getValidInput(): to verify the input, then prints the vitamins benefits
Code:
def printWelcome():#HEre we print the welcome message
print("Welcome In this program we learn about vitamins and its
uses")
def getValidInput():#HEre we take the valid Input from the
user
choice=int(input("Enter Your Choice:"))
while(choice<0 or choice>5):
print("Invalid Input Enter Again")
choice=int(input("Enter Your Choice:"))
return choice
def main():
printWelcome()#printing the welcome message
while(True):#infinet while loop
print("0.Exit")
print("1.Vitamin A")
print("2.Vitamin B6")
print("3.Vitmain B12")
print("4.Vitamin C")
print("5.Vitamin D")#printing the menu
choice=getValidInput()#taking user input
if(choice==0):
print("Bye bye!")#if choice is 0
break
elif(choice==1):#if choice is 1
print("Vitamin A protects eyes from night blindness and age-related
decline\n")
elif(choice==2):#if choice is 2
print("Vitamin B6 promotes brain health and reduces Alzheimer's
risk\n")
elif(choice==3):#if choice is 3
print("Vitamin B12 may improve health by decreasing
homo-cysteine\n")
elif(choice==4):#if choice is 4
print("Vitamin C protects your health from cardiovascular issues,
cancer and strokes\n")
elif(choice==5):#if choice is 5
print("Vitamin D reduces the risk of diabetes\n")
main()
Output:
Indentation: