Programming in     

minutes

Python

60

What is programming?

Programming is the process of taking an algorithm and encoding it into a notation, a programming language, so that it can be executed by a computer.

HUH??

An algorithm is a set of instructions to complete a task

A notation is a method of representing something by a special system

We use programming languages (notation) to represent our instructions (algorithms)

Computers run these programs and complete our tasks!

In simpler terms...

We want a task done!

We create a set of instructions

We write these instructions in a programming language

The computer runs this program

The computer does this task for us!

In even more simpler terms...

We program to make our lives easier! We make our computers do our tasks for us!

Introducing

Python is used in...

Python

Web development

Instagram

Pinterest

Trivago

Data Science

Software Prototyping

Let's get started and code in Python!

Online compilers lets us run our code without us having to download any software 

print()

Used to send output to your computer screen

Hello, world!
My name is ___.
I am learning Python!

Exercise: Can you try printing this to your screen?

Can print different data types 

Is a built-in function

More on these points later...

Basic Data Types

Used to represent different types of data

<class 'float'>
<class 'bool"'>

Exercise: Can you try printing this to your screen?

strings

boolean (True/False)

integer, floats (decimal numbers)

type() tells you the data type 

type(<data>)
<class 'str'>
print(type("hello world"))

Built-in Functions

Used to complete a specific task

print("Hello, world!")
type(4.0)

Exercise: What is the task of print()? What is the task of type()?

Can be re-used whenever necessary!

Python provides these functions without us having to do anything!

Variables

Used to store some data and pull it out later

Variables are like containers, store some data, pull it out later

The Variable Song (by Colt Steele)

x = 3
print(x)
name = "sheeza"
print(name)
#Variable Syntax
#<var> = <expression>
  • Variables must start with a letter or underscore character
  • Variables must only contain alpha-numeric and underscores
  • Variables are case-sensitive

Variable Naming Rules

Exercise: Can you try printing this to your screen by using a variable for your name?

Hello, world!
My name is ___.
I am learning Python!

Basic Operators

Used to perform mathematical or logical operations

+ addition

- subtraction

* multiplication

/ division

 

== equal to

!= not equal to

< less than

> greater than

<= less than or equal to

>= greater than or equal to 

num1 = 1
num2 = 2
print(num1 + num2)
print(num1 * 3)

Exercise: Determine the output of this program?

print(3 > 2)
print(2 == (1+1))
print(4 / 2)

input()

Used to receive input from the user

input("Please enter a number: ")

Exercise: Use an input prompt to get the user's name and then print out their name

Can store this input in a variable

user_num = input("Please enter a number: ")

This input is read as a string

The program does not continue until the user provides an input

My name is __.
I am __ years old.

Exercise 2: Print the following:

float()

Used to convert numbers in strings to floating point numbers

wage = 16.75
weekly_hours = input("How many hours a week do you work?: ")
#weekly_salary = ?
print("You make", weekly_salary, "per week!")

Exercise: Complete the code to calculate the weekly salary of a user

temperature = input("Please enter the current temperature of your area")
temperature = float(temperature)
print("41") # '41'
print(float("41")) # 41.0

If statements

Used to complete a task if a condition is true

Exercise: Create a variable password and store some text in it. Ask the user for their password and if the user_password matches the password, print "welcome, user!"

In other words, used to make decisions for our programs

if <condition>:
  <do something>
elif <conditon>:
  <do something different>
else:
  <do something different>

Recap

Built-in Functions

Used to complete a specific task

The ones we learnt are:

print() - prints output to the screen

type() - tells you the data type

input() - gets input from the user

float() - converts numbers in strings to floats

 

Variables

Used to store data so that we can reuse it later

Recap

Basic Operators

Data Types

Used to represent different types of data

The ones we learnt are:

strings

boolean (True/False)

integer, floats (decimal numbers)

Used to perform mathematical or logical operations

The ones we learnt are:

== equal to

!= not equal to

< less than

> greater than

+ addition

- subtraction

* multiplication

/ division

<= less than or equal to

>= greater than or equal to 

Mini Project Using Everything We've Learnt!

What should you wear?

If temperature is less than 0 degrees Celsius, you should wear a jacket, scarf, and mittens

If temperature is in between 0 and 15 degrees Celsius, you should wear a light coat

If temperature is greater than 15 degrees Celsius, you should wear a light shirt

Can you see this in code?

Introduction to Programming with Python

By sheeza aziz

Introduction to Programming with Python

For a workshop held by FemINStem (feminstem.ca). Feel free to reach out to me for speaker notes!!

  • 319