Skip to main content

Primitive: Integer, float, boolean, None, and string are primitive data types because they represent a single value.

Containers: Other data types like list, tuple, and dictionary are often called data structures or containers because they hold multiple pieces of data together.

  • numbers

    • strings

    • booleans

  • Operations

    • addition

    • multiplication

    • division

    • subtractions

    • doesn't work on booleans

Boolean Operators

  • and

  • or

How to convert a conceptual problem into an iterative algorithm:

  • Identify the sequence of steps.

  • Start at the initial state (e.g., x = 1).

  • Apply repeated transformations (e.g., compute x^2 until it matches some condition).

  • Determine:

    • The counting variable.

    • The end test.

    • How the variable changes each iteration.

  • Finish with a clear end statement.

Assignment

  • Bind a name to a value (creating variables).

Input and Output

  • print() to display results.

  • input() to receive user data (optional at this stage).

  • Conditionals

  • Decision-making: changing the flow of control.

    • Branches (if, elif, else)

    • Direct the program through different sequences of instructions.

Loop Mechanisms

  • while loops for repeating blocks of instructions.

  • Choose the variable that will change
    (often a counter or an element from a collection).

  • Initialize the variable

    • Initialization always happens outside the loop.

  • Set the end condition

    • Determine how the loop knows when it is done.

  • Construct the loop body

    • A block of instructions repeated each iteration.

    • This block typically:

      • Updates the data structure.

      • Changes the loop variable.

      • Avoids infinite loops by modifying the controlling variable.

  • Define what happens when the loop finishes

    • Output results or return values.

Execution time depends only on the number of instructions.

Does not depend on the input size.

Logical paths are fixed.

Each “box” or step is executed once.

The number of loop iterations grows with the size of the input.

Example: if the input increases by 5, the loop takes 5 extra iterations.