Count paths through a repair branch

A receipt routine uses three Boolean inputs: chooseText, repair, and runAdd. Each can independently be true or false, giving eight distinct input combinations. Indentation identifies the statement controlled by each if.


In the dynamic version, variables may change value types. Addition accepts only two integers, performs no conversion, and stops the routine on a type error. A successful print displays one number.


Plain text
var amount = 10
if chooseText:
    amount = "10"
if repair:
    amount = 6
if runAdd:
    print(amount + 4)


In the static version, the first line is instead var amount: Int = 10. Integer variables may receive only integers, and analysis rejects an incompatible assignment anywhere in the source before execution, including inside a branch.


Across the eight input combinations, determine the following exact whole-number counts, each to zero decimal places:

  • Combinations that print a number in the dynamic version.
  • Combinations that fail with a type error in the dynamic version.
  • Combinations for which the static version can begin executing.

Evaluate the assignments in their written order.

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 Type Systems Questions: