0% found this document useful (0 votes)
13 views26 pages

Introduction to Python Programming Course

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views26 pages

Introduction to Python Programming Course

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Alright — welcome to Year 1, Semester 1, Course 1: Introduction to Programming I.

Think of this as your first day in a Canadian software engineering lecture hall — except the snacks are
optional and nobody will steal your seat.

---

📚 Lecture 1: Introduction to Programming with Python

Course Overview

This course will teach you:

How to think like a programmer

Python syntax and structure

Writing, running, and debugging code

Problem-solving with algorithms

---

1. What is Programming?
Programming is the process of giving instructions to a computer so it can perform tasks.

Computers don’t “understand” human language — they follow precise, step-by-step instructions written
in a programming language.

A program is like a recipe:

Ingredients = Data

Steps = Code instructions

Chef = The CPU executing the instructions

---

2. Why Python?

Python is:

Beginner-friendly

Used by Google, NASA, and YouTube

Versatile (web apps, AI, data analysis, automation)


Has readable syntax close to English

Example:

print("Hello, world!")

This simple program prints text to the screen.

---

3. How Programs Run

Step 1: You write the code (source code)

Step 2: Python interpreter translates it into machine code

Step 3: CPU executes the instructions

---

4. Your First Program

Here’s the “Hello World” in Python:


# This is a comment

print("Hello, world!")

Anything after # is ignored by Python (comments help you document your code)

print() is a function that outputs text

Try changing "Hello, world!" to your name.

---

5. Variables

Variables are names that store data.

Example:

name = "Tredom"

age = 20

print("My name is", name)

print("I am", age, "years old")


name stores text ("Tredom")

age stores a number (20)

---

🎯 Assignment 1

Write a Python program that:

1. Stores your name in a variable

2. Stores your age in another variable

3. Prints:

Hello, my name is [YourName] and I am [YourAge] years old.


---

If you complete that, in Lecture 2 we’ll dive into data types, input, and basic math in Python — the real
start of problem-solving.

Do you want me to give you a quick guide on how to set up Python on your phone or computer so you
can run the code yourself starting today?

Here’s how to set up Python on your phone or computer, step-by-step, so you can start coding right
away.

---

🐍 Python Setup Guide

Option 1: Android Phone (Quickest)

If you’re on Android, you can run Python without a laptop.

Step 1: Install a Python IDE

Go to Google Play Store

Search for “Pydroid 3” (free)

Install it – this app comes with Python 3 built-in.


📱 Alternative Apps:

QPython 3L (lightweight, also free)

Termux (advanced, for command-line lovers)

---

Step 2: Run Your First Code

1. Open Pydroid 3

2. Tap “Editor” → paste this code:

print("Hello, world!")

3. Tap the yellow play button ▶️

4. You should see:


Hello, world!

🎉 Congrats — you just ran your first Python program on your phone!

---

Option 2: Computer (Laptop/PC)

If you have a computer, this is better for serious software engineering practice.

Step 1: Install Python

Go to [Link]/downloads

Download Python 3.x (latest stable version)

Install it, and check the box that says "Add Python to PATH" during installation.

---
Step 2: Verify Installation

1. Open Command Prompt (Windows) or Terminal (Mac/Linux)

2. Type:

python --version

3. You should see something like:

Python 3.12.1

---

Step 3: Install a Code Editor

For serious coding, install VS Code:

Download: [Link]
Install it, then add the Python extension from the Extensions menu.

---

Option 3: No Installation Needed

If you can’t install apps, use an online Python editor:

[Link]

[Link] (create a free account)

Just paste your code, hit Run, and see results instantly.

---

Assignment After Setup

Once you’ve set it up, run this program:


name = "Tredom"

age = 20

print("Hello, my name is", name, "and I am", age, "years old.")

If it works, you’ve completed Lecture 1 fully.

Next, we’ll move to Lecture 2: Data Types, Input, and Basic Math — the real building blocks of
programming.

Would you like me to prepare Lecture 2 now, or do you want to try running the assignment first and
show me what you got?

Great! Let's move straight to Lecture 2 of your Introduction to Programming I course.

Make sure your Python setup is ready on your phone or computer because you'll be writing and running
code today.

---

📚 Lecture 2: Data Types, Input, and Basic Math

In this lesson, we’ll cover:

1. Python data types (how Python stores and understands different kinds of data)

2. Taking user input


3. Doing math with Python

4. A mini-project at the end

---

1. Python Data Types

Data types are like labels that tell Python what kind of data it’s dealing with.

Here are the most important ones for now:

Data Type Example Description

String (str) "Hello" Text, inside quotes

Integer (int) 10 Whole numbers

Float 3.14 Decimal numbers

Boolean (bool) True or False Logical values


---

Examples:

# Strings

name = "Tredom"

# Integer

age = 20

# Float

height = 5.9

# Boolean

is_student = True

---

2. Checking Data Type

Python can tell you the data type using type().

Example:
x = 10

print(type(x)) # Output: <class 'int'>

y = "Hello"

print(type(y)) # Output: <class 'str'>

---

3. Taking User Input

To make programs interactive, we use input().

Example:

name = input("Enter your name: ")

print("Hello,", name)

> Note: Everything from input() is treated as text (string), even numbers.

---
Converting Input to Numbers

If you want to perform math, you must convert the input.

Example:

age = int(input("Enter your age: ")) # Converts to integer

print("You will be", age + 1, "next year.")

---

4. Basic Math Operations

Python can perform all basic math operations.

Operator Use Example (a = 10, b = 3) Result

+ Addition a+b 13

- Subtraction a-b 7

* Multiplication a * b 30

/ Division (float) a / b 3.33

// Division (integer) a // b 3

% Modulus (remainder) a%b 1

** Exponent (power) a ** b 1000


---

Example: Calculator

num1 = float(input("Enter first number: "))

num2 = float(input("Enter second number: "))

sum_result = num1 + num2

print("The sum is:", sum_result)

---

5. Mini Project: Simple Age Calculator

🎯 Goal: Create a program that:

1. Asks for your name and birth year

2. Calculates your current age


3. Prints:

Hello Tredom, you are 20 years old.

Hint:

current_year = 2025

---

Assignment

1. Run the age calculator program.

2. Modify it so it tells you how old you’ll be in 5 years.

3. Share your code with me, and I’ll check it like a professor would.
---

Would you like me to prepare Lecture 3, where we’ll dive into decision-making in code (if/else
statements), or do you want to try the assignment first?

Alright! Let’s keep building your programming skills.

We’re now moving to Lecture 3, which is one of the most important topics in programming: decision-
making using if statements.

---

📚 Lecture 3: Decision Making in Python (if, elif, else)

Programs need to make decisions, just like humans do.

Example:

If it’s raining → take an umbrella ☔

Else → wear sunglasses 😎

In programming, this is done using conditional statements.


---

1. The if Statement

The if statement allows your program to run code only when a condition is true.

Syntax:

if condition:

# Code to run if condition is true

Example:

age = 18

if age >= 18:

print("You are an adult.")

Output:

You are an adult.

> Important: The colon : and indentation (spaces at the start of the line) are required in Python.
---

2. Adding else

The else block runs if the condition is false.

Example:

age = 16

if age >= 18:

print("You are an adult.")

else:

print("You are a minor.")

Output:

You are a minor.

---

3. Multiple Conditions with elif


Sometimes you need more than two choices.

Use elif (else if).

Example:

score = 75

if score >= 90:

print("Grade: A")

elif score >= 80:

print("Grade: B")

elif score >= 70:

print("Grade: C")

else:

print("Grade: F")

---

4. Comparison Operators

These are used to compare values in conditions.

Operator Meaning Example Result


== Equal to 5 == 5 True

!= Not equal to 5 != 3 True

> Greater than 10 > 5 True

< Less than 3<5 True

>= Greater than or equal to 7 >= 7 True

<= Less than or equal to 6 <= 8 True

---

5. Logical Operators

Combine multiple conditions.

Operator Meaning Example

and Both conditions must be true age >= 18 and age <= 60

or At least one condition must be true age < 18 or age > 60

not Reverses the condition not(age >= 18)

---
6. Example: Voting Eligibility Checker

age = int(input("Enter your age: "))

if age >= 18:

print("You are eligible to vote!")

else:

print("Sorry, you are not old enough to vote.")

---

7. Mini Project: Grading System

🎯 Goal:

Write a Python program that:

1. Takes a student’s score as input.

2. Prints their grade based on the following rules:

90 and above → A

80–89 → B
70–79 → C

60–69 → D

Below 60 → F

Example Output:

Enter your score: 85

Grade: B

---

Assignment

1. Write and test the grading program.

2. Modify it to also print a message like:


A → "Excellent work!"

B → "Good job!"

C → "Keep improving!"

D → "You passed, but study harder."

F → "Failed. You need to retake this course."

---

Next Lecture Preview – Lecture 4

We’ll learn about loops (for and while), which allow you to repeat actions automatically — the key to
writing efficient programs.

Would you like me to prepare Lecture 4 now, or do you want to try the grading project first and show
me your code?

Common questions

Powered by AI

Variables and data types are fundamental in programming, as they allow programmers to store and manipulate data efficiently. Variables act as named storage for data, which can be used and modified throughout a program. Meanwhile, data types define the kind of data variables can hold, ensuring that operations on them are logical and valid. Together, they enhance program efficiency by enabling correct data handling and reducing errors .

Running a Python program involves three key steps: writing the code, translating it into machine code using an interpreter, and executing the instructions by the CPU. Understanding each step is crucial for a beginner because it highlights the transformation of human-readable instructions into a format that the computer can process, reinforcing the importance of clear and precise coding .

Basic mathematical operations in Python, such as addition, subtraction, multiplication, division, and modulus, are foundational for developing simple calculator applications. These operations allow beginners to see the practical applications of programming in solving everyday mathematical problems. This fosters computational thinking and reinforces the importance of accuracy and logic in programming .

Logical operators in Python, such as 'and', 'or', and 'not', allow for the combination and inversion of conditions within if statements. These operators enhance the complexity by enabling intricate condition evaluations, such as checking multiple criteria simultaneously or negating a condition's outcome. This increased complexity allows for more sophisticated decision-making processes within programs .

Taking user input is crucial for creating interactive applications. In Python, user input is initially treated as a string, regardless of content. Converting this input to appropriate data types, such as integers or floats, is important for conducting calculations or logic operations. This conversion ensures that the input is correctly interpreted and utilized within the program, enhancing its functionality and user interaction .

Mini projects like an age calculator are significant in learning Python as they integrate multiple programming concepts—such as variables, user input, data conversion, and output formatting—into a cohesive task. This hands-on application challenges learners to synthesize their knowledge, apply logic, and solve real-world problems, thus promoting a deeper understanding and retention of programming concepts .

Python can be set up on Android devices via Python IDEs, such as Pydroid 3, allowing for a mobile coding experience. For more serious programming practice, a computer setup is recommended. This involves installing Python from python.org and using a code editor like VS Code, which supports advanced features through extensions. Different setups cater to varying levels of programming engagement, from casual coding on mobile to professional development on a computer .

Comments in Python are lines of text within code that are ignored during execution. They serve as documentation, helping programmers and collaborators understand the purpose and functionality of code segments. Comments are crucial for clarifying logic, noting potential improvements, and simplifying debugging, thus supporting the problem-solving process by providing context and guidance .

Conditional statements in Python allow programs to execute certain segments of code based on specific conditions, mimicking decision-making processes. Key components include 'if', 'elif', and 'else' statements, which provide multiple paths for program execution based on evaluated conditions. Comparison and logical operators are used within these statements to articulate the conditions .

Python is considered suitable for beginners due to its beginner-friendly syntax that is similar to English, which simplifies learning for new programmers. Additionally, Python’s versatility allows it to be used in various domains such as web development, AI, and data analysis, among others. Its wide adoption by major organizations like Google and NASA highlights its robust performance and reliability .

You might also like