1 of 18

WEEK 6

Introduction to

Python Programming

From print statements to for loops

BinaryTree

2 of 18

Last Week's Recap & Introduction

BinaryTree

  • Last week: Web development — what makes a website objectively good or bad
  • Covered how HTML, CSS, and JavaScript work together to build websites
  • This week: Introduction to Python — syntax, data types, variables, and conditionals
  • Goal: Write your first Python programs using BinaryTree's online IDE

3 of 18

What Is Python?

BinaryTree

  • Created in 1991 — designed as a high-level, general-purpose programming language
  • One of the most popular languages in the world due to its readability and simple syntax
  • Beginners can pick it up quickly; professionals use it at the highest level
  • Great for automating repetitive tasks — and plays a huge role in machine learning
  • Used at companies like Google, Netflix, NASA, and Instagram

4 of 18

Setting Up Python: BinaryTree IDE

BinaryTree

How to Get Started

  • Choose an IDE you're comfortable with — there are online and desktop options
  • This course uses BinaryTree's Python IDE (no installation needed)
  • Open your browser and go to: https://www.binarytree.us/ide.html
  • The IDE will open directly in your browser — ready to code

5 of 18

Python Features & Theory

BinaryTree

Libraries

Python has a massive library ecosystem: PyTorch (ML), PyGame (games), random, math, requests, pandas, and thousands more.

Community

One of the largest programming communities in the world. Extensive documentation and solutions to nearly every common error exist online.

Syntax

No curly braces — Python uses indentation and colons. No need to declare variable types. Simpler to read than Java or C++.

6 of 18

Python vs. C++: Speed & Efficiency

BinaryTree

Why Python Is Slower

  • Uses an interpreter — executes code line-by-line at runtime
  • Each line must be converted to machine code as it runs
  • Dynamic typing: variable types determined at runtime (type checks slow execution)
  • Automatic garbage collection adds overhead
  • High-level abstraction = more steps to reach machine code

Why C++ Is Faster

  • Uses a compiler — converts all code to machine code before running
  • Compiler makes optimizations during compilation
  • Static typing: variable types declared before runtime (faster execution)
  • Manual memory management — developers control allocation/deallocation
  • Low-level language — closer to machine code

7 of 18

DISCUSSION

Because Python has more forgiving syntax than Java or C++, would Python be more efficient overall?

Explain why or why not.

BinaryTree

8 of 18

Python Fundamentals

BinaryTree

9 of 18

Data Types in Python

BinaryTree

Python

# Numeric

x = 42 # int

y = 3.14 # float

# Text

name = "Hello, World!" # str

# Boolean

is_valid = True # bool

# Sequence

my_list = [1, 2, 3] # list (mutable)

my_tuple = (4, 5, 6) # tuple (immutable)

Numeric (int, float), Text (str), Boolean (bool), and Sequence (list, tuple) are the core types.

10 of 18

Variables: Declaration and Scope

BinaryTree

Python

# Declaring a variable (no type needed!)

my_name = "BinaryTree"

age = 16

gpa = 3.8

# Global variable (accessible anywhere)

global_var = "I am global"

def my_function():

local_var = "I only exist here" # local

print(global_var) # can access global

print(local_var)

my_function()

Variables store data. Scope determines where a variable is accessible — local (inside a function) or global.

11 of 18

Hello, World! & Print Statements

BinaryTree

Python

# The classic first program

print("Hello, World!")

# Printing a variable

message = "Hello from BinaryTree!"

print(message)

# Printing multiple values

first = "Binary"

last = "Tree"

print(first, last) # outputs: Binary Tree

Always put strings in quotes. When printing a variable, do NOT use quotes around the variable name.

12 of 18

Task: Store and Print

BinaryTree

Store "Hello, World!" into a variable, then print it.

Solution

greeting = "Hello, World!"

print(greeting)

# Note: Use double quotes for strings.

# Single quotes are reserved for single characters (chars in other languages).

13 of 18

User Input with input()

BinaryTree

Python

# The input() function gets text from the user

name = input("What is your name? ")

print("Hello,", name)

# Input always returns a string!

age_str = input("How old are you? ")

age = int(age_str) # Convert to integer

print("In 5 years you will be", age + 5)

input() returns a str. Convert to int with int() or float with float() before doing math.

14 of 18

Math Operators & Assignment Operators

BinaryTree

Python

# Math operators

x = 10 + 3 # addition = 13

x = 10 - 3 # subtraction = 7

x = 10 * 3 # multiplication = 30

x = 10 / 3 # division = 3.333...

x = 10 // 3 # floor division = 3

x = 10 % 3 # modulus (remainder) = 1

x = 10 ** 2 # exponentiation = 100

# Assignment operators (shortcuts)

x += 5 # same as x = x + 5

x -= 2 # same as x = x - 2

x *= 3 # same as x = x * 3

Use ** for exponents (not ^). Modulus % gives the remainder — useful for checking even/odd.

15 of 18

If-Else Conditionals

BinaryTree

Python

number = int(input("Enter a number: "))

if number > 0:

print("Positive")

elif number < 0:

print("Negative")

else:

print("Zero")

# Checking even or odd

if number % 2 == 0:

print("Even")

else:

print("Odd")

elif = "else if". Indentation defines the block — Python uses whitespace, not curly braces.

16 of 18

Task: Odd or Even Checker

BinaryTree

Using arithmetic operators and if-else conditionals, write a program that tells whether a user-entered integer is even or odd.

Solution

n = int(input("Enter an integer: "))

if n % 2 == 0:

print(n, "is even")

else:

print(n, "is odd")

17 of 18

Conclusion

BinaryTree

  • Python is a beginner-friendly, high-level language — but powerful enough for professional use
  • Simple syntax makes it accessible, though it trades speed for readability compared to C++
  • Key concepts covered: print(), input(), variables, data types, operators, if-else
  • Next week: Data structures (lists, tuples, dictionaries) and libraries

18 of 18

Thank You!

That wraps up Week 6. See you next week!

Next: Week 7: Intermediate Python Programming

BinaryTree