Getting Started with Python
Getting Started with Python
Learning Objectives:
What is Python?
Python is a popular, beginner-friendly programming language used in web
development, data science, automation and more.
What is a Variable?
A variable is like a container or label that stores information. You give it a name,
and it holds a value.
age = 15
name = "Ali"
In this example:
Python automatically knows what type of value you're storing. Here are the most
common types:
🧪 Example:
name = "Sara" # str
age = 13 # int
height = 1.55 # float
is_student = True # bool
Quick Tips:
print("Hello, world!")
Notice that the word print is placed in a particular colour as it is a Python key word.
("Hello, world!") is a string so it is in quotation marks “”. We use parentheses because
print is a function. A function is like a command that does something. When you use a
function, you call it with parentheses () — and you can pass information into it.
Now that we can print letters and words, lets get into printing numbers.
🔸 Printing Numbers
print(42)
print(3.14)
You can print whole numbers (integers) and decimal numbers (floats).
🔸 Doing Math
Python can do basic math just like a calculator:
● Add 12 and 8
● Multiply 7 by 6
● Divide 25 by 5
Learning Objectives:
🔸 What is a Variable
A variable is like a container or label that stores information.
age = 15
name = "Ali"
Python automatically knows what type of value you're storing. Here are the most
common types:
🧪 Example:
name = "Sara" # str
age = 13 # int
height = 1.55 # float
is_student = True # bool
Quick Tips:
🔸 B. Simple Calculators
Let users input numbers to perform math operations.
🔸 E. Decision-Making Programs
Ask questions and give different outputs based on input.
if choice == "1":
print("Hello!")
elif choice == "2":
print("Goodbye!")
age = 18
if age == 18:
age = 16
if age == 18:
age = 14
if age == 18:
else:
🧪 Example to try:
color = input("Enter a color: ")
if color == "red":
print("Stop!")
print("Go!")
else:
● Their name
● Favorite food
● Favorite animal
Example:
🧠 Learning Objectives:
● Use if statements to make decisions
Here's another explanation for if, else, and elif (which means "else if") in Python.
age = 18
if age == 18:
age = 16
if age == 18:
age = 14
if age == 18:
else:
🧪 Example to try:
color = input("Enter a color: ")
if color == "red":
print("Stop!")
print("Go!")
else:
import random
# Welcome message
if guess == secret_number:
How it works:
1. The program randomly chooses a number between 1 and 10.
import random
while True:
else:
● The while True: loop keeps running forever — until the player guesses
correctly.
● The break statement stops the loop when the guess is correct.
● The game gives feedback if the guess is too high or too low.
== equal to
!= not equal to
if answer == "Paris":
print("Correct!")
else:
🧠 Bonus: Add more questions and keep score! As you practice more and
more you can turn this into a fun trivia game.
❌ Not allowed:
1score = 25 # ❌ Starts with a number
3. No spaces allowed
Words like if, else, print, input, etc., are reserved by Python and can’t be used as variable
names.
❌ print = 20
✅ my_print = 20
6. Names are case-sensitive
score = 10
Score = 20
Bonus Tips 💡:
✅ ❌
● Choose names that make sense:
age = 15 is better than a = 15
Comments are notes we put in so that when we look at the code in the future, we can
follow along easily. Use the # symbol to start a comment:
Prepared by Mr. Job T. Gumbs Eng. April 16th 2025
M.A.D. Scientist
17
# This is a comment
print("Hello") # This prints Hello to the screen
Comments are not required, but they're very helpful for writing clean,
understandable code — especially as your programs get bigger!
What is Casting?
⚠️ Important:
The string must actually look like a number, or you'll get an error:
✅
# This works:
int("25") #
❌
# This will crash:
int("hello") # Error!
🧪 Example:
num1 = input("Enter a number: ")
num2 = input("Enter another number: ")
The type() function in Python tells you the data type of a value or variable.
F = 7.3 + 4
print(type(F))
So it prints:
<class 'float'>
🧠 Quick Tip:
Adding an int and a float always gives a float
🧪 Optional Homework:
Create a short program that:
3. If they’re under 18, prints: “Keep having fun with [hobby]!”
4. If they’re 18 or older, prints: “Nice! Hope you still enjoy [hobby]!”