---
title: Python Lesson 25/09/2026
description: "Python is somewhat STRICT. They require capital letter for their True and False. For the current lesson (as of 25/09/2026). These includes: boolean (True/False) and values (e.g. in error handling ValueError, KeyboardInterrupt). ## Selection It is used everywhere. And I…"
url: "https://surden.me/documentation/python-lesson-25-09-2026/"
updated: "2026-09-25"
category: Oaklands College / Python Lessons
---

# Python Lesson 25/09/2026

Python is somewhat STRICT. They require capital letter for their True and False. For the current lesson (as of 25/09/2026). These includes: boolean (True/False) and values (e.g. in error handling ValueError, KeyboardInterrupt).

## Selection

It is used everywhere. And I mean EVERYWHERE. It is basically a question. Example:

```
name = "John"
if name == "JOHN":
    print("Hi John")
else:
    print("You are not John..")

# This program will output the false result "You are not John..". This is because it is explicitly looking for the input "JOHN".

# To mitigate this, we will be using the lower() method. This will make our input into all lower cases. There is also upper() method. Use either method to modify the code.
```

Remember **Parent and child** method. Parent is an example of a function (def), and the child is the code RELATED to that parent. The child MUST BE at least 1 space to the right (indentation). And all children must follow one another unless they belong to another parent underneath.

## Functions

Functions must be called for it to work. Functions never run until called by the program.

Example:

```
# DEAD till called
def calculate(a,b):
    if a > b:
        return a
    else:
        return b

# Calling the function
print(calculate(10, 120))
```

If the function is not called, nothing will run. There are also recursive functions - but that is a bit of a pain to deal with.

## Iterations: For Loops

For loops are just counting from 0 to whatever number you are thinking of. For example, **for x in range(10)**. This will count from 0 to 9! 0 counts as the first index/integer. Example of how to use this for loop:

```
# For loop from 0 to 2, displaying +1 so it counts 1 to 3.
for x in range(0,2):
    print(x + 1)

# This will print: 1, 2, 3

# For loop for a list or array. Can be achieved by using the  len() function.

daysOfTheWeek = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
for x in range(0, len(daysOfTheWeek):
    print(daysOfTheWeek[x])

# This should loop 7 times, starting from index 0. Index 0 will be "Monday" as all list starts from index 0. We start from position 0 (range(0, len(...)) as that is the first index of the list. If we use 1 or another number, it will result in the error IndexError.
```

## Iterations: While Loops

This is a loop where it can go on forever if not stopped properly. It can only trigger if the condition is True OR meet the required condition (e.g. name = "john").

The loop will continue until a break is introduced or the condition no longer meets. Here is an example:

```
# In this example, I will be showing how to ask the user for their password, and will only allow the user to continue IF they have met the requirements. Do not use this for production as it is very insecure.

# Creating the variable "storedPassword" to hold our password we want as the system.
storedPassword = "password123@"

# Now we ask for the password for the first time.
passwordInput = str(input("Enter password: "))

# Note we use a string. This is to be explicit but is not required in python.

# Starting the while loop.
while passwordInput != storedPassword:
    # Ask the user for the password again
    passwordInput = str(input("Wrong, try again: "))

# Now we validate the password in case something goes wrong above.

if storedPassword != passwordInput:
    print("Access denied")
else:
    print("Access granted")
```

## Try / Except clauses (error handling)

A very useful thing to do for most codebases. We want the users to be able to keep using the service or software and not crash the entire system. From ATM machines running out of money, to a radio.

In python, there are 2 main things you need to know for this to work. (try and except), these will be how you TRY to run the code, and add EXCEPTIONS in case the software goes wrong. Here is an example of preventing users from inputting anything that is not a number:

```
# First we TRY the code

# We will be using while loop for this demonstration
while True:
    try:
        number = int(input("Enter an integer (no decimals): "))
        if number == 10:
            print("Right number!")
            break
    except ValueError:
        print("Please make sure you are using an integer.")
```
