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
USING PYTHON. Thank you in advance Write a program that allows the user to enter a...
USING PYTHON. Thank you in advance Write a program that allows the user to enter a series of string values into a list. When the user enters the string ‘done’, stop prompting for values. Once the user is done entering strings, create a new list containing a palindrome by combining the original list with the content of the original list in a reversed order. Sample interaction: Enter string: My Enter string: name Enter string: is Enter string: Sue Enter string:...
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...
Create a Python program that: Allows the user to enter a phrase or sentence. The program...
Create a Python program that: Allows the user to enter a phrase or sentence. The program should then take the phrase or sentence entered Separate out the individual words entered Each individual word should then be added to a list After all of the words have been place in a list Sort the contents of the list Display the contents of the sorted list with each individual word displayed on a separate line Display a message to the user indicating...
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
Write, save, and run a Python program Ask the user to enter a number of grams....
Write, save, and run a Python program Ask the user to enter a number of grams. Your program converts that to whole tones, then whole kilograms and whatever is left is in grams. It prints the entered grams , tones , kilograms and the remaining grams.      4 marks for i in range(0,10): print(i) 2    what is wrong in the above python code? display your explanation using print statement. mark 3    insert the following comments into your program of part...
Write a Python Program Continue to ask the user to enter a POSITIVE number until they...
Write a Python Program Continue to ask the user to enter a POSITIVE number until they type DONE to quit. The program should DOUBLE each of the digits in the number and display the original entry AND the SUM of the doubled digits. Hint: Use the // and % operators to accomplish this. Print the COUNT of entries that were invalid Examples: if the user enters 93218, the sum of the doubled digits is 18+6+4+2+16 = 46. User Entry Output...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT