Danulearn Open Danulearn
Unit 6

Fundamentals of Programming

๐Ÿ“—Introduction
  • A software program is written in a programming language.
  • Like human languages, programming languages have their own rules, called syntax, which define how instructions are written.
  • Python relies on indentation to define scope and uses a new line to complete a command.
  • The semantics of a program is the meaning of what is written.
  • In Grade 11 you met programming languages, basic Python syntax and simple programs.
  • This unit adds the constructs that control the flow of a program โ€“ conditionals and loops โ€“ and then covers comments, the Python interpreter, and testing and debugging.
๐ŸŽฏ Learning Outcomes
  • Explain program flow controls.
  • Describe conditional program flow control.
  • Describe iteration program flow control.
  • Construct program statements using control statements.
  • Appreciate the Python interpreter using an Integrated Development Environment (IDE).
  • Analyse program statements in debugging mode.
6.1  Program Flow Controls and Syntax in Python
  • Program flow control is the order in which a program's code executes.
  • In Python it is regulated by three programming constructs, or kinds of program logic: sequential, branching and loop.
  • Sequential โ€“ statements are executed one after another in the order given (declaring variables, reading input, printing output). Example: following a recipe step by step.
  • Branching (conditional) โ€“ the program chooses one of two or more alternatives, depending on a condition. Example: if it rains, I take an umbrella.
  • Loop (iteration) โ€“ a statement or group of statements is repeated. Example: recording the marks of 50 students, one after another.
6.1.1Conditional Program Flow Controls
  • Sometimes a program must choose between alternatives depending on its input.
  • A program that decides whether a number is even or odd is an example: a number is even if the remainder after dividing it by two is zero (num % 2 equals 0), and odd otherwise.
  • Python provides conditional, or branching, statements for such problems.
Conditional expression
  • A conditional expression uses comparison operators or the Boolean operators and, or and not.
  • It evaluates to one of the two Boolean values, True or False.
  • For example 3 == 4 is False.
DescriptionIn PythonIn mathematics
Equalsa == ba = b
Not equala != ba โ‰  b
Less thana < ba < b
Greater thana > ba > b
Less than or equal toa <= ba โ‰ค b
Greater than or equal toa >= ba โ‰ฅ b
Remember: A single equals sign (=) is the assignment operator: height = 2.5 stores the value 2.5 in the variable height. A double equals sign (==) compares: height == 2.5 asks whether height is equal to 2.5 and gives True or False.
๐Ÿ”’
The rest of Unit 6 is in the Danulearn app

Read the full notes for all 4 sections, worked examples and figures, plus 13 exercises with step-by-step solutions, the Short Note and the unit review.

๐Ÿ“‘ Contents

  1. 6.1Program Flow Controls and Syntax in PythonPreview
  2. 6.2Comments in Python๐Ÿ”’
  3. 6.3Python Interpreter๐Ÿ”’
  4. 6.4Testing and Debugging Programs๐Ÿ”’