Chapter 5 Review Questions Multiple Choice, Exercises 1, 2, 3
Chapter 5 Review Questions Multiple Choice, Exercises 1, 2, 3
5. A(n) __________ loop has no way of ending and repeats until the program is interrupted.
a. indeterminate
b. interminable
c. infinite
d. timeless
8. A(n) __________ is a special value that signals when there are no more items from a
list of items to be processed. This value cannot be mistaken as an item from the list.
a. sentinel
b. flag
c. signal
d. accumulator
10. The integrity of a program’s output is only as good as the integrity of the program’s
a. compiler
b. programming language
c. input
d. debugger
11. The input operation that appears just before a validation loop is known as the
a. prevalidation read
b. primordial read
c. initialization read
d. priming read
Chapter 5, Exercise 1
Chapter 5 Review Questions Multiple Choice, Exercises 1, 2, 3
#constant
NUMDAYS = 7
def main():
total = 0
print("Enter the number of insects collected")
for day in range(NUMDAYS):
text = "Day [{}] = "
print(text.format(day+1))
collected = int(input(" "))
total += collected
print("The total number of insects collected was : ", total)
Chapter 5 – Exercise 2
# Hugo Hiraoka @COP1047 | Assignment 3, Chapter 5, Exercise 2
# -----------------------------------------------------------
#2. Calories Burned
#Running on a particular treadmill you burn 3.9 calories per minute. Write a program
#that uses a loop to display the number of calories burned after 10, 15, 20, 25, and 30
#minutes.
#constant
CALPERMIN = 3.9
INITIALTIME = 10
TIMEINCREMENT = 5
FINALTIME = 30
def main():
for calburn in range(INITIALTIME,FINALTIME+1,TIMEINCREMENT):
calories = calburn*CALPERMIN
print("Calories burnt at ", calburn, "min = ", calories)
Chapter 5 – Exercise 3
# Hugo Hiraoka @COP1047 | Assignment 3, Chapter 5, Exercise 3
# -----------------------------------------------------------
def main():
totalexpenses = 0
more_expenses = 'y'
budget = float(input("Enter the budget amount = $"))
while more_expenses == 'y':
expense = float(input("Enter the expense = $"))
totalexpenses +=expense
more_expenses = input("Do you want to enter more expenses (Enter y for Yes): ")
print("The total expenses were $", format(totalexpenses, ",.2f"))
if (budget - totalexpenses) > 0.0:
print("You were under budget by $", format(budget-totalexpenses, ",.2f"))
elif (budget - totalexpenses) < 0.0:
print("You were over budget by $", format(budget-totalexpenses, ",.2f"))
else:
print("You were exactly on budget.")