The cost of moving an else

A festival checkout has two versions of its ticket-pricing code. Each version starts independently, and both inputs are either True or False.


Program A


Python
price = 40
if has_pass:
    price = 28
    if evening:
        price = 22
    else:
        price = 25


Program B


Python
price = 40
if has_pass:
    price = 28
    if evening:
        price = 22
else:
    price = 25


Across all four combinations of the two inputs, how many combinations produce different final prices in the two programs? Also find each program's final price when has_pass = False and evening = True. Give the count as an exact integer and both prices in dollars to the nearest whole dollar.

Your answers

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Nested Decisions Questions: