Question

In: Computer Science

In Python, write a program that allows the user to enter a number between 1-5 and...

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:

  • Continue to run until the user quits and
  • Validate the user’s input (the only acceptable input is 0, 1, 2, 3, 4, or 5),
  • If the user enters zero “0” the program should terminate

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

Solutions

Expert Solution

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:


Related Solutions

In Python, write a program that allows the user to enter a number between 1-5 and...
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: Continue to run until the user quits and Validate the user’s input (the only acceptable input is 0, 1, 2, 3, 4, or 5), If the user enters zero “0” the program should terminate You can use the following facts: 1- Vitamin A protects eyes from night blindness and age-related decline...
Write a program that runs on SPIM that allows the user to enter the number of...
Write a program that runs on SPIM that allows the user to enter the number of hours, minutes and seconds and then prints out the total time in seconds. Name the source code file “seconds.asm
Write a program that runs on SPIM that allows the user to enter the number of...
Write a program that runs on SPIM that allows the user to enter the number of hours, minutes and seconds and then prints out the total time in seconds. Name the source code file “seconds.asm Explain step by step
Write a MATLAB program to do the following: 1- Allows the user to enter unlimited number...
Write a MATLAB program to do the following: 1- Allows the user to enter unlimited number of data set. 2- Allows the user to exit the program at any time by entering zero. 3- Calculates and displays the following statistics for the entered data set: a- Count of positive, negative, and total numbers. b- Maximum and Minimum numbers. c- Sum and Average of positive numbers. d- Sum and Average of negative numbers. e- Overall Sum and overall average of all...
PYTHON: Write a program that asks the user to enter a 10-character telephone number in the...
PYTHON: Write a program that asks the user to enter a 10-character telephone number in the format XXX-XXX-XXXX. The application should display the telephone number with any alphabetic characters that appeared in the original translated to their numeric equivalent. For example, if the user enters 555-GET-FOOD, the application should display 555-438-3663. This is my code, but I cannot figure out where to go from here. #set new number new_number = "" #split number split_num = phone.split("-") for char in split_num[1:2]:...
Write a python program which asks the user to enter a positive number that is greater...
Write a python program which asks the user to enter a positive number that is greater than 30 called, “num2” and then does the following: o 1) Print all numbers between 1 and “num2” that are divisible by 2 and 3. o 2) Print all numbers between 1 and “num2” that are either divisible by 6 or 7. o 3) Print all numbers between 1 and “num3” that is not divisible by 5
Please write in Python code please: Write a program that asks the user to enter 5...
Please write in Python code please: Write a program that asks the user to enter 5 test scores between 0 and 100. The program should display a letter grade for each score and the average test score. You will need to write the following functions, including main: calc_average – The function should accept a list of 5 test scores as an input argument, and return the average of the scores determine_grade – The function should accept a test score as...
In C#, write a console-based program that asks a user to enter a number between 1...
In C#, write a console-based program that asks a user to enter a number between 1 and 10. Check if the number is between the range and if not ask the user to enter again or quit. Store the values entered in an array. Write two methods. Method1 called displayByVal should have a parameter defined where you pass the value of an array element into the method and display it. Method2 called displayByRef should have a parameter defined where you...
In Python write a program that asks the user to enter the monthly costs for the...
In Python write a program that asks the user to enter the monthly costs for the following expenses incurred from operating his or her automobile: loan payment, insurance, gas, oil, tires, and maintenance the program should then display the total monthly cost of these expenses, and the total annual cost of these expenses. your program MUST have BOTH a main function AND a function named calcExpenses to calculate the expenses. DO NOT display the expenses inside of the calcExpenses function!!...
Please write the code JAVA Write a program that allows the user to enter the last...
Please write the code JAVA Write a program that allows the user to enter the last names of five candidates in a local election and the number of votes received by each candidate. The program should then output each candidate’s name, the number of votes received, and the percentage of the total votes received by the candidate. Your program should also output the winner of the election. A sample output is: Candidate      Votes Received                                % of Total Votes...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT