BinaryTree
BinaryTree
Digital Literacy Program
Digital Literacy and Digital Entrepreneurship
BinaryTree
Week 5
Introduction to Python Programming
Last Week's Recap & Introduction
What is Python?
Setting Up Python
https://www.binarytree.us/ide.html
Basic Python Theory & Features
Discussion
Because Python has more forgiving syntax than Java or C++, would Python be more efficient in general?
Explain why or why not.
Python vs. C++ – Efficiency
Python is NOT faster than C++ or Java. Here's why:
Data Types
Variables
x = 42 name = "Alice" is_active = True
Hello, World!
print("Hello, World!")
message =
"Hello"
(message) # print a variable — no quotes!
Task
5 min
Store "Hello, World" into a variable, then print it.
Getting User Input
name = input("What is your name? ")�print("Hello, " + name)
Task
5 min
Create a program that asks the user for something to print, then prints it. Use input(), a variable, and print().
Python Operators
Math Operators:
Assignment Operators:
Task
5 min
Write a program that sets any integer variable x to itself divided by 5, then adds 3 to that result.
Converting Between Data Types
num_str = input("Enter a number: ")�num = int(num_str) # now it's an integer
Task
5 min
Take a number from the user via input(), add 5 to it, then print the result.
Hint: You need to convert the input from str to int first.
If-Else Conditionals
x = 10
if x > 5:
print("Greater than 5")
elif x == 5:
print("Equal to 5")
else:
print("Less than 5")
Task
6 min
Using arithmetic operators and if-else conditionals, write a program that tells whether an integer is even or odd.
Hint: use the modulus operator %.
Conclusion
BinaryTree
Thank You For Attending!
Next week: Intermediate Python — data structures, libraries, and real-world applications!