← All lessons

Lesson 5

Interactive Python Programs and Real-World Applications

Item 1

Object-Oriented Programming (OOP)

OOP organizes code into classes and objects. A class is a blueprint; an object is an instance of that class with its own attributes (data) and methods (functions).

Class — A blueprint for creating objects.
Object — An instance of a class.
Attribute — Data stored in an object.
Method — A function inside a class.

Try it — edit the code and press Run:

Item 2

Functional Programming (FP)

Functional programming builds programs from small functions. Tools like lambda, map() and filter() apply functions to data.

lambda — A small anonymous function.
map() — Applies a function to every item.
filter() — Keeps items that pass a test.

Try it — edit the code and press Run:

Item 3

From Scripts to Software

Real software combines input, decisions, loops, data structures and functions into one organized program — often with a menu the user can interact with.

Script — A short program that runs top to bottom.
Menu — A list of options the user chooses from.

Try it — edit the code and press Run:

Item 4

Types of Errors in Python

Syntax errors break the grammar rules (missing colon or bracket). Runtime errors happen while running, like NameError, TypeError and ZeroDivisionError. Logical errors give wrong results without any message.

SyntaxError — Code breaks Python grammar.
NameError — Using a variable that is not defined.
TypeError — Wrong type in an operation, e.g. 5 + "5".
Logical error — Code runs but gives the wrong answer.

Try it — edit the code and press Run:

Quick Quiz

1. What is a class?

2. What error does print(x) give if x is not defined?

3. Why does 5 + "5" cause an error?

4. Which error gives a wrong result with no message?

5. What does map() do?

Score: 0 / 5(Sign in to save your score)

Practice

Auto-checked exercises at three levels. Open hints one by one before the solution.

⭐Basic

Fix the error

This code has a NameError. Fix it so it prints: Welcome Sara

⭐⭐Intermediate

Safe division

Use try/except to print 10 / 0. If it fails print "Error".

⭐⭐⭐Challenge

Car class

Create class Car with attribute brand and method info() that prints "Car: <brand>". Create Car("BMW") and call info().

Smart Assistant Project

Task 5: The Smart Assistant

Goal: Combine everything into one interactive program.

Requirement: Build a menu: 1) Add student 2) Show all students with grades 3) Exit. Use a list of dictionaries, functions, loops and try/except for invalid input.