What is coding?
_________________l3s2bj
Lesson 1
Kl;”
_l2
What Is Coding?
Let’s discuss programming
➔ What are computer programs?
➔ What do programmers do?
PYTHON CODE EXAMPLE
def display_game_winner(player_wins,
computer_wins):
if player_wins > computer_wins:
print("Player wins the series!")
print(player_victory_ascii)
elif computer_wins > player_wins:
print("Computer wins the series!")
print(computer_victory_ascii)
Else:
print("The series tied!")
Coding Is
Teaching a computer
how to perform a task
➔ Computers are not smart machines.
➔ They will do whatever you tell them to do
Why Python?
Introducing Python!
➔ In this course, we program in Python.
➔ Python is great for beginners,
because it has simple syntax and
helpful libraries for common tasks.
?
➔ Python is a general-purpose
programming language.
➔ Python is used in data science, AI,
machine learning, and web development.
Data Types &
Variables
Lesson 2
Strings and Integers
Fundamental data types
➔ Today, we’ll learn two data types:
STRINGS and INTEGERS.
SYNTAX SLIDE
"some text"
Strings are
enclosed in
quotes
Strings
Strings are surrounded by double or single quotes.
SYNTAX SLIDE
"This is a string"
"1" # This is a string as well!
"" # This is an empty string.
Strings (continued)
A string can be a number. A string can also be empty.
Anything surrounded by quotes is a string!
SYNTAX SLIDE
3
42
128134901487
Integers
Integers are whole numbers. They are not surrounded by
quotes.
Variables
Storing data with
➔ To store data, like a string or an integer,
you can use a variable.
➔ Variables assign names to values.
➔ Using a name instead of a value
makes code read like English.
Rules for
Naming Variables
So start
Cannot we putwith
that a
data into boxed
number
containers called
Cannot contain spaces.
variables.
Cannot contain special
characters
except _ (underscore)
Two variables cannot have
same name.
SYNTAX SLIDE
"Django"
2
Introducing Variables
What do these two values represent? “Django” is a name, but what is
2? Variables will give these values meaning.
SYNTAX SLIDE
dog_name = "Django"
age = 2
The assignment
operator
Introducing Variables ( continued )
This is how you create a variable. Now we know what the values represent!
The assignment operator (=) assigns a value to a variable. You can also think of it
as assigning a name to a value.
DATA VS VARIABLES
car_model = "BMW"
year = 2025
play_game(“Roblox”)
favorite_movie = "Minions"
33
timer(5)
Conditional
Statements
Lesson 3
The
If it's
switch is
sunny,
In real world up, light
you don’t
flow of bulb
wear a
turns on.
jacket. event
changes
depending
upon other
things. If it’s
If below
1/4th of a Saturday
tank, fill or Sunday,
up on gas. wake up
late.
var_name = True If - else
condition
if var_name: with
# if var_name is true this part boolean
works variable
else:
# if it's not, then this part
works.
EXAMPLE
humidity = True
if humidity:
weather = ‘cloudy’
else:
weather = ‘sunny’
Not all
conditions
are yes/no
type
conditions.
if a > 10:
If a is greater than 10
Relational
Operators
if a < b: You can use both
variables and
If a is less than b numbers.
if a == 100:
if a equals one hundred
if a >= 10:
If a is greater than or equal
to 10
Relational
Operators
if a <= b: You can use both
If a is less than or equal to variables and
b numbers.
if a != 100:
if a is not equal to one hundred
EXAMPLE
humidity = 52
if humidity > 50:
weather = ‘cloudy’
else:
weather = ‘sunny’
Functions
Lesson 4
SYNTAX SLIDE
do_something()
What’s a function?
A word with () at the end indicates a function.
SYNTAX SLIDE
add_background( "filename.ext" )
Name of the
function Image filename
Adding a background
The add_background() function needs the filename of the image to do
its job.
SYNTAX SLIDE
add_rocket()
Empty
parentheses
Adding a rocket
The add_rocket() function doesn’t need any information to do its
job, so the parentheses are empty.
( ) means this
instruction is a
function.
Each function is
actually set of
something() instructions
already written
for you.
Name of the
instruction
Define a
function
def function_name(): and then
# do something call the
function.
function_name()
Rules for
Function Names
So we put that
Start with a letter or an
data into boxed
underscore: _.
containers called
variables.
They can have numbers.
They can be any length
They can't be the same as
a Python keyword.
PROGRAMMING SYNTAX
enter_launch_code("RAINMAKER")
start_count_down(10)
launch()
killIgnition()
That's
almost
English
!
FUNCTION MATCHING
1. split() A: A function to see the largest integer in a list
2. print() B: A function that allows taking user input
3. round() C: A function that converts strings to lowercase
4. max() D: A function that breaks up a string
5. lower() E: A function that rounds up a number
6. join() F: A function that joins string items in a list
7. input() G: A function that prints a string
Function
Arguments
Lesson 5
Functions can
accept
variables
called
ARGUMENTS.
Creating a
def function_name(var_1, function
var_2): that
# do something with var_1, accepts
variables.
var_2
function_name(value_1, value_2)
What is the
def add_numbers(x, y): result of
total = x + y addNumber
s?
return total
result = add_numbers(1, 2)
PROGRAMMING SYNTAX
enter_launch_code("RAINMAKER")
start_count_down(10)
launch()
kill_ignition()
DEFINE AND CALL A FUNCTION
1. A function that subtracts two numbers
2. A function that returns a value
3. A function with a variable
4. A function with a conditional statement
5. A function with two arguments