replit

Before you start this course, you must login to Replit

If you have forgotten your Replit account user name or password, ask your Coder Coach.

CoderSports


PRIMM Task – Predict & Run

At the ‘predict’ & ‘run’ stages students work entirely with example code. They should inspect it carefully and write a prediction about what it will do.

They then run the code and compare the result to their prediction.


Advanced If…Else Statements – Nesting

Nesting is the term for putting programming constructs of the same type inside each other.

These examples use nested if statements – if statements inside other if statements.

The nested statement will only be run if the condition above it is True.

if num1 > 20:
  print("Bigger than 20")

# nested if is indented so is part of the 'if' statement above.
  if num1 > 50:
    print("and bigger than 50")
  else:
    print("but not bigger than 50")

Errors & Misconceptions To Watch Out For

  • Check the indentation very, very carefully
  • Count the ifs & elses, are there an equal number?
  • Check your logic, when should each branch run? Is the if statement nested into the correct branch – try drawing out a flowchart on paper to map the possible pathways through the program.

Hints