The purpose of each function should be documented? The purpose of each while-loop should be documented? The program runs def main(): totalBottles = 0 counter = 1 todayBottles = 0 totalPayout = 0 keepGoing = "y" while keepGoing.lower() == "y": totalBottles = getBottles() totalPayout = calcPayout(totalBottles) printInfo(totalBottles, totalPayout) print("Do you want to enter another week’s worth of data?") print("(Enter y or n)") keepGoing = input() def getBottles(): NBR_OF_DAYS = 7 totalBottles = 0 todayBottles = 0 counter = 1 while counter <= NBR_OF_DAYS: print(f"Enter number of bottles returned for day #{counter}:") todayBottles = int(input()) totalBottles += todayBottles counter += 1 return totalBottles def calcPayout(totalBottles): PAYOUT_PER_BOTTLE = .10 totalPayout = totalBottles * PAYOUT_PER_BOTTLE return totalPayout def printInfo(totalBottles, totalPayout): print(f"Total number of bottles returned for the week: {totalBottles}") print(f"Total payout for the week: ${totalPayout:.2f}") main()
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.
- The purpose of each function should be documented?
- The purpose of each while-loop should be documented?
The
def main():
totalBottles = 0
counter = 1
todayBottles = 0
totalPayout = 0
keepGoing = "y"
while keepGoing.lower() == "y":
totalBottles = getBottles()
totalPayout = calcPayout(totalBottles)
printInfo(totalBottles, totalPayout)
print("Do you want to enter another week’s worth of data?")
print("(Enter y or n)")
keepGoing = input()
def getBottles():
NBR_OF_DAYS = 7
totalBottles = 0
todayBottles = 0
counter = 1
while counter <= NBR_OF_DAYS:
print(f"Enter number of bottles returned for day #{counter}:")
todayBottles = int(input())
totalBottles += todayBottles
counter += 1
return totalBottles
def calcPayout(totalBottles):
PAYOUT_PER_BOTTLE = .10
totalPayout = totalBottles * PAYOUT_PER_BOTTLE
return totalPayout
def printInfo(totalBottles, totalPayout):
print(f"Total number of bottles returned for the week: {totalBottles}")
print(f"Total payout for the week: ${totalPayout:.2f}")
main()
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images