program4_1.py Write a program that prompts a dieter to enter in their caloric budget (as an integer) for the week. After accepting and storing that value, use a while loop to accept and process the caloric value for each meal (entered as an integer value). Within the while loop keep a running total of the caloric values of the meals entered and a count of the meals entered. Terminate the while loop when the dieter enters 0. After the while loop ends, print the count of meals entered and print a message (follow the examples in the example outputs) indicating whether the dieter's caloric total intake was at, above, or below their caloric budget. Printed output messages will vary based on input but related output should be formatted as in the example outputs. The ellipsis is being used to represent missing values that your program should also generate.
Types of Loop
Loops are the elements of programming in which a part of code is repeated a particular number of times. Loop executes the series of statements many times till the conditional statement becomes false.
Loops
Any task which is repeated more than one time is called a loop. Basically, loops can be divided into three types as while, do-while and for loop. There are so many programming languages like C, C++, JAVA, PYTHON, and many more where looping statements can be used for repetitive execution.
While Loop
Loop is a feature in the programming language. It helps us to execute a set of instructions regularly. The block of code executes until some conditions provided within that Loop are true.
program4_1.py
Write a program that prompts a dieter to enter in their caloric budget (as an integer) for the week. After accepting and storing that value, use a while loop to accept and process the caloric value for each meal (entered as an integer value). Within the while loop keep a running total of the caloric values of the meals entered and a count of the meals entered. Terminate the while loop when the dieter enters 0. After the while loop ends, print the count of meals entered and print a message (follow the examples in the example outputs) indicating whether the dieter's caloric total intake was at, above, or below their caloric budget.
Printed output messages will vary based on input but related output should be formatted as in the example outputs. The ellipsis is being used to represent missing values that your program should also generate.
The algorithm of the code is given below:-
1. Print a statement asking the user to enter their caloric budget for the week.
2. Set a variable, caloric_budget, equal to the user's input.
3. Set a variable, caloric_total, equal to 0.
4. Set a variable, meal_count, equal to 0.
5. Create a while loop that runs while meal_calories is not equal to 0.
6. Print a statement asking the user to enter the caloric value of the meal.
7. Set a variable, meal_calories, equal to the user's input.
8. If meal_calories is equal to 0, break out of the loop.
9. Otherwise, add meal_calories to caloric_total and increment meal_count by 1.
10. Print a statement showing the user how many meals they entered and the total calorie value.
11. If caloric_total is above caloric_budget, print a statement saying that the calorie budget is above the caloric intake.
12. If caloric_total is below caloric_budget, print a statement saying that the calorie budget is below the caloric intake.
13. If caloric_total is equal to caloric_budget, print a statement saying that the calorie budget is equal to the caloric intake.
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images