Python Programming for Beginners
From Variables and Conditions to Functions and Practical Problem Solving
An original study guide for students and early-stage programmers
Learning objective: Build a clear mental model of Python and develop the ability to turn simple
problems into working programs.
Python Programming for Beginners • Page 1
Contents
Section Topic
1 Getting Started with Python
2 Variables and Data Types
3 Operators and Expressions
4 Conditions: if, elif and else
5 Loops and Repetition
6 Functions
7 Lists and Basic Data Handling
8 Problem-Solving Method
9 Practice Exercises
10 Next Steps
Python Programming for Beginners • Page 2
1. Getting Started with Python
Python is a general-purpose programming language designed to make programs relatively easy to read
and write. It is widely used for automation, data analysis, web development, scientific computing and
machine learning.
How a Python program works
A program is a sequence of instructions. A useful beginner mindset is: input → processing → output.
name = input("Enter your name: ")\nprint("Hello,", name)
input() collects information, the variable name stores it, and print() displays a result.
Good beginner habits
• Read error messages carefully instead of guessing.
• Use meaningful variable names.
• Change one part of a program at a time when debugging.
• Practice writing small programs rather than only reading examples.
2. Variables and Data Types
A variable is a name that refers to a value. Variables allow a program to remember information and use
it later.
age = 22\nname = "Aisha"\nheight = 1.68\nis_student = True
Common built-in data types include int for whole numbers, float for decimal numbers, str for text, and
bool for True/False values.
Checking a type
value = 25\nprint(type(value))
3. Operators and Expressions
Operators perform actions on values. Arithmetic operators include +, -, *, /, //, %, and **.
total = 10 + 5\nproduct = 4 * 3\nremainder = 17 % 5\nsquare = 6 ** 2
Comparison operators such as ==, !=, >, <, >= and <= produce Boolean results. Logical operators and,
or and not combine or reverse conditions.
score = 75\nprint(score >= 50)
4. Conditions: if, elif and else
Conditional statements allow a program to choose what to do based on a condition.
score = 72\n\nif score >= 80:\n print("Excellent")\nelif score >= 50:\n print("
Pass")\nelse:\n print("Needs improvement")
Python Programming for Beginners • Page 3
Python uses indentation to show which statements belong to a block.
Decision-making pattern
• Identify the condition.
• Decide what should happen when it is True.
• Add alternative conditions if needed.
• Provide a fallback with else when appropriate.
5. Loops and Repetition
Loops repeat instructions. A for loop is useful when iterating over a sequence or known range. A while
loop continues while a condition remains True.
for number in range(1, 6):\n print(number)
count = 1\nwhile count <= 5:\n print(count)\n count += 1
Common loop errors
• Forgetting to update a while-loop condition can create an infinite loop.
• Using the wrong range endpoint can produce one extra or one fewer iteration.
• Incorrect indentation can change which statements are repeated.
6. Functions
A function is a reusable block of code that performs a particular task. Functions help divide a larger
problem into smaller pieces.
def calculate_square(number):\n return number ** 2\n\nresult = calculate_square(5)
\nprint(result)
The parameter receives an input. return sends a result back to the place where the function was called.
Why functions matter
• They reduce repeated code.
• They make programs easier to test.
• They separate tasks into understandable units.
• They make future changes easier.
7. Lists and Basic Data Handling
A list stores multiple values in a single ordered collection.
scores = [72, 85, 91, 68]\nprint(scores[0])\nprint(len(scores))
Indexing starts at 0, so scores[0] is the first item.
for score in scores:\n print(score)
Python Programming for Beginners • Page 4
A simple calculation
total = 0\nfor score in scores:\n total += score\naverage = total / len(scores)\np
rint(average)
8. A Practical Problem-Solving Method
Programming becomes easier when you separate the problem from the code. Before typing, describe
what the program must accomplish.
Five-step method
• Understand the problem: identify the required result.
• Identify inputs: determine what information is available.
• Define processing: write the calculations or decisions needed.
• Define output: decide exactly what the user should see.
• Test: try normal, boundary and unexpected cases.
Example: calculate profit
If a shop has a cost price and a selling price, profit can be calculated as selling price minus cost price.
cost_price = 500\nselling_price = 650\nprofit = selling_price - cost_price\nprint("Pr
ofit:", profit)
The important skill is recognising the relationship between inputs, processing and output.
9. Practice Exercises
First write the algorithm in plain language, then convert it into Python.
• 1. Print the numbers from 1 to 10.
• 2. Print the numbers from 10 down to 1.
• 3. Print all even numbers between 1 and 20.
• 4. Ask for a number and determine whether it is positive, negative or zero.
• 5. Ask for a student's marks and display Pass or Fail.
• 6. Write a function that returns the square of a number.
• 7. Calculate the total cost of five items.
• 8. Calculate profit or loss from cost price and selling price.
• 9. Find the largest number in a list.
• 10. Calculate the average of a list of numerical values.
10. Next Steps
Once variables, conditions, loops, functions and lists feel comfortable, combine them into small projects
such as a calculator, number-guessing game, expense tracker, student-grade calculator or simple
Python Programming for Beginners • Page 5
data-processing script.
For scientific work, Python can later be extended with tools for numerical computing, data manipulation,
visualisation, statistics and machine learning. The same core reasoning remains important: understand
the problem, structure the data, process it systematically, and verify the result.
Quick revision checklist
• I can explain what a variable is.
• I can identify common Python data types.
• I can use arithmetic and comparison operators.
• I can write if/elif/else decisions.
• I can use for and while loops.
• I can define and call a function.
• I can work with a basic list.
• I can break a problem into input, processing and output.
• I can test a program using more than one example.
End of study guide
Python Programming for Beginners • Page 6