Introduction to Programming and Python
Topics Covered
● Programming basics
● Variables & data types
● Input & output
Learning Objectives
● Understand what programming is and why Python is used
● Run a basic Python program
● Use variables and basic data types
● Collect user input and display output
1. Introduction to Programming
1.1. What is Programming?
Programming is how we tell computers what to do. Think of it like giving step-by-step
instructions to a very smart assistant who follows them exactly. These instructions are written
in code, which is like a special language that computers understand. The people who write
code are called programmers.
1.2. Why Learn Programming?
● It helps you solve problems with technology.
● You can automate boring tasks, like sorting files or sending emails.
● It lets you create websites, apps, and even games!
2. Getting Started
Just as there are many ways through which we humans communicate with each other, such as
speaking or sign language, there are also multiple ways we can communicate with
computers.
We could use a picture-based system (like icons on your desktop), voice-based systems,
command-line-based systems, and many more.
In this course, we will focus on the command-line-based system (CLI).
A command line is a text-based interface where a user can interact with a computer by typing
commands on a tool called a terminal.
2.1. Why Choose the Command Line?
● Running commands in the terminal is quicker than navigating through menus and
windows in a picture-based system.
● CLI programs consume fewer system resources and don’t require heavy graphical
processing.
● Developers can manipulate files, manage networks, install software, and troubleshoot
systems with precision.
● Most programming tools (compilers, version control like Git, databases) have powerful
CLI options that enhance productivity.
You may find these later in your coding journey—but don’t be afraid of research!
2.2. The Various Ways to "Write Text-Based Commands"
A good portion of the most renowned programming languages fall under this category. You
may have heard of JavaScript, Python, Ruby, C, C++, and many others.
These languages all have their own histories and common areas of use.
For example:
● JavaScript is preferred for web development.
● C++ is preferred for robotics and high-performance applications.
● Python is widely used for automation, AI, and scientific computing.
They also have different rules for grammar, called syntax, and many other components that
we shall dive into later.
2.3. Why Are We Focusing on Python?
For this competition, we will focus on Python for a couple of reasons:
● Easy to learn – The code reads almost like English, so you don’t have to wrestle with
complex syntax.
● Versatile – It works for web development, data science, AI, automation, and much
more.
● Huge community – Very many tutorials, libraries, and support from other users.
● Cross-platform – Runs smoothly on different operating systems without needing
major changes.
2.4. What can Python do?
● Python can be used on a server to create web applications.
● Python can be used alongside software to create workflows.
● Python can connect to database systems. It can also read and modify files.
● Python can be used to handle big data and perform complex mathematics.
● Python can be used for rapid prototyping, or for production-ready software
development
2.5. Famous Application Built using Python
● YouTube: World’s largest video-sharing platform uses Python for features like video
streaming and backend services.
● Instagram: This popular social media app relies on Python’s simplicity for scaling and
handling millions of users.
● Spotify: Python is used for backend services and machine learning to personalize
music recommendations.
● Dropbox: The file hosting service uses Python for both its desktop client and
server-side operations.
● Netflix: Python powers key components of Netflix’s recommendation engine and
content delivery systems (CDN).
● Google: Python is one of the key languages used in Google for web crawling, testing
and data analysis.
● Uber: Python helps Uber handle dynamic pricing and route optimization using
machine learning.
● Pinterest: Python is used to process and store huge amounts of image data efficiently.
3. Learning Python
Python is a popular programming language created by Guido van Rossum and released in
1991.
Contrary to popular belief, it was not named after a snake but rather a comedy series called
Monty Python’s Flying Circus.
3.1. Your First Program
a. Open your IDE
An IDE (Integrated Development Environment) is an application that provides everything
needed for programming in one place.
b. Type the following code:
#This is a comment. It will not be executed
print("Hello, World!")
c. Press the run button to run the program.
What happened?
The phrase "Hello, World!" appeared on the screen!
We just successfully wrote and ran a Python program.
How does this work:
a. print() is a built-in Python function that tells the computer to show something on the
screen.
b. The message "Hello, World!" is a string, which means it's just text. In Python, strings
are always written inside quotes (either single ' or double ").
c. Anything after # in a line is a comment. Python ignores comments when running the
code, but they help people understand what the code is doing.
d. Comments are helpful for explaining code, making notes or skipping lines while
testing.
We can also write multi-line comments using triple quotes:
"""
This is a multi-line comment.
It can be used to describe larger sections of code.
"""
4. Diving Deeper: The Basics
Now that we’ve explored Python’s importance and setup, let's dive into the fundamental
building blocks of programming. These concepts are essential to writing clear, efficient, and
interactive code.
4.1. Data Types – Numbers, text, and other data formats.
Computers work with data, which is just information. A data type determines the kind of
information that can be stored and used throughout your program.
Examples:
● Integers (int) – whole numbers like 1, 50, -3, 100
● Floats (float)– decimal numbers e.g. 3.0, 58.895, -1.245
● Strings (str) – words or sentences, written in quotation marks: "Peter", "This is fun"
● Booleans (bool) – represent True or False, useful for decisions in programs.
● Lists – a list is an ordered, mutable (can be changed after creation) collection of items.
Example: my_list = [1, 2, "apple", 3.14]
● Tuples – A tuple is an ordered, immutable (cannot be changed after creation) collection
of items. Example: my_tuple = (1, 2, "apple", 3.14)
● Sets – A set is an unordered, mutable collection of unique items.
Example: my_set = {1, 2, "apple", 3.14}
● Dictionaries – A dictionary is an ordered, mutable collection of key-value pairs.
Example: my_dict = {"name": "John", "age": 30, "city": "New York"}
We shall look at lists, tuples, sets and dictionaries further in the course.
Operations Table
Operation Symbol Example Result
Addition + 5+3 8
Subtraction - 10 - 4 6
Multiplication * 7*2 14
Division / 9/3 3.0
Modulus % 10 % 3 1
(remainder after
division)
Exponentiation ** 2 ** 3 8
(raising to the power
e.g 2 to the power 3)
Try these in Python! Type them one by one and see the output.
4.1.1. String Concatenation
To concatenate is to combine two or more strings into a single one.
For example; You have been tasked to collect the full names of your classmates for a program
that roll calls students in the morning. This is one way you could do it.
first_name = "Mary"
last_name = "Elizabeth"
full_name = first_name + " " + last_name
print(full_name) # Output: Mary Elizabeth
Note: Always include spaces explicitly when joining words!
4.1.2. Using f-strings (Recommended):
For example; Write a program that introduces a person called Esther and their age, 25 years.
name = "Esther"
age = 25
print(f"This is {name} and she is {age} years old.")
# Output: This is Esther and she is 25 years old.
4.2. Variables – How computers store data
Variables are used to store information to be referenced and manipulated in a computer
program. Think of variables as containers that hold information.
4.2.1. Declaring Variables
a. Declaring a variable: You assign a name to a piece of data using the = operator.
b. Using the variable: Once declared, you can reference the variable to perform
operations, calculations, or other tasks.
In Python, declaring variables is simple and does not require explicitly specifying the type.
Python determines the type of the variable based on the value assigned to it. Here are some
examples:
i. Basic Variable Declaration
# Integer
age = 25
# Float
price = 2.4
# String
name = "Alice"
# Boolean
is_active = True
ii. Multiple Variables in One Line
# Assigning the same value to multiple variables
x = y = z = 10
# Assigning different values to multiple variables
a, b, c = 1, 2.5, "Hello"
iii. Using Descriptive Names
# Always use meaningful variable names for clarity
user_name = "John316"
total_price = 150.75
is_logged_in = False
Example: Write a program to declare your current age and your age next year.
# Declare a variable
age = 25 # 'age' now holds the value 25
# Use the variable
print("I am", age, "years old.") # Outputs: I am 25 years old.
# Modify the variable
age += 1 # Increment age by 1
print("Next year, I will be", age, "years old.") # Outputs: Next year, I will be 26 years old.
If you did not get this result, check your spelling and capitalization. This process is
called debugging – finding and fixing errors in a program.
4.2.2. Naming and Using Variables
Follow these rules:
● Variable names can contain only letters, numbers, and underscores.
● They must start with a letter or underscore (_), not a number.
● Use underscores instead of spaces.
● Don’t use Python keywords (like print) as variable names.
● Use short but descriptive names.
● Be careful with lowercase l and uppercase O, as they resemble 1 and 0.
4.2.3. Worked Exercises
Exercise 1:
Write a program that welcomes Patience to python programming
name = "Patience"
print("Hello, " + name + "! Welcome to Python.")
Exercise 2:
Write variables for each of the data types you have learned and print them.
num = 10
decimal = 5.5
text = "Python"
is_learning = True
print(num, decimal, text, is_learning)
By now, you should have noticed that different parts of the code are written in different
colors. This is called syntax highlighting. Parts which serve the same function have the
same color, e.g. variables are blue in this case. The color combinations you get depend
on the IDE you’re using and the settings of your IDE.
4.3. Collecting User Input & Displaying Output
4.3.1. User Input
We can ask users to enter data, then store it in variables. For this we use input() to ask the
user for data.
e.g. Write a program that collects the names of your favourite teachers and prints them
name = input("Enter your name: ")
print(f”Teacher ” {name} “is the best”)
You can convert the input to a specific type like this:
int(input()), str(input()), float(input()), bool(input())
This is called typecasting.In Python, typecasting refers to converting one data type into
another. This is often done to ensure compatibility between different data types or to perform
specific operations.
For example
If we wanted to add two numbers that a user has input, we would get an error if the user put in a string
instead of a number.
# ask a user for two numbers e.g. 1 and 2
num_1=input(“Enter a number: ”)
num_2=input(“Enter a number: ”)
sum=num_1 + num_2
print (sum)
#output would be 3
#but if the user put “three” as one of the numbers, we would get a type error because
strings and integers cannot be added
#To fix this, specify the type of data a user should put in.
num_1=int(input(“Enter a number: ”))
num_2=int(input(“Enter a number: ”))
sum=num_1 + num_2
print (sum)
4.3.2. Displaying Output
Here we use the print() function that we have been using to print out variables and other
results.
We can also use it to find the different data types of our variables by integrating the type()
function into it
e.g.
a = "Hello World"
b = 10
c = 11.22
print(type(a))
print(type(b))
print(type(c))
“””output is :
<class 'str'>
<class 'int'>
<class 'float'>”””
5. Mini Project: Age Calculator
Goal: Build an interactive program that calculates a user's age.
birth_year = int(input("Enter your birth year: "))
age = 2025 - birth_year
print("You are", age, "years old.")
Bonus Challenge:
Try to calculate the user's age in months and days!
6. Wrapping Up Week 1
● You’ve learned variables, data types, input/output, and debugging!
● You’ve built a mini age calculator project!
● You understand how Python code works in a CLI environment!
Next week, we'll dive into control flow and logic!