Professional Documents
Culture Documents
Get Into Programming With Python: Programming Is Being in Control
Get Into Programming With Python: Programming Is Being in Control
Programming
with Python
Programming is being
in control
If you can answer the following
questions, then you can write a
computer program:
1. What comes next 3,6,9…?
2. Can you operate a microwave?
3. Can you name the steps to bake a
cake, change a tire or assemble a
piece of furniture?
Info about Presentation and presenter name below
Variables,
Constants,
Types and
Axle Barr Name Here Name here
Casting
• Details about the • Details about the • Details about the
presenter/instructor presenter/instructor presenter/instructor
• Details about the • Details about the • Details about the
presenter/instructor presenter/instructor presenter/instructor
• Details about the
presenter/instructor
Why Use Variables
What is a variable:
green_bucket
Filling Buckets
Pour the contents of the red and blue buckets into the green:
red_bucket
Blue bucket
Red bucket
Green bucket
Algorithm to
Program
Translating this to an actual computer program, it will look like this
red_bucket = 300
blue_bucket = 200
green_bucket = 0
Algebra Computer
Program
• There are certain values that do not change, such as the number of
days in a week, degrees in a circle and wheels on a tricycle. The constant
• Some mathematical constants, like pi and Euler’s number (e), do not variable?
change
01
Use storage based on purpose:
• Computers use memory (RAM) space to store the value that a variable
represents
01
• Printing and inputting data can only
be done with one type, Strings. To
print any data type other than a
string, we must convert that type into
a string, temporarily.
• We can cast any other type into a
string
• Casting does NOT change the type of
the original variable, only in the
process of printing does the type
change
name = "John"
age = 44
print("Hello " + name + ", your age is " + str(age))
name = "John"
print("Hello", name)
name = "John"
age = 44
print("Hello", name, age)
name = "John"
age = 44
print("Hello %s your age is %d" % (name, age))
Place holders replace Recycle bins with specific content:
content
• Think of placeholders like %d and %s
as recycle bins.
CANS PAPER PLASTIC LANDFILL
• The bins are empty at first, but they
have a label, cans, paper etc.
• As users finish their meals, they
throw the appropriate type of waste
into the appropriate bins.
• Same with %d, only numbers can be
thrown into that placeholder and
then printed out.
Place holders replace Chest of drawers with
content specific content:
t-Shirts
Another way to look at placeholders is Socks
a chest of drawers. The top drawer may
be designated
Another way to look atas the sockisdrawer,
placeholders a chest of a
drawers.
Thedifferent
top drawerone
may for underwear
be designated as theand
sockadrawer,
third a
different one for underwear
for t-shirts and athey
etc. At first, third for
aret-shirts
empty etc. At
first they are empty but once filled at anytime in the future
butyouonce filled
can open theat anytime
sock drawer andin find
thesocks.
future Shorts
you can open the sock drawer and find
socks. Open the t-shirts drawer and
find only t-shirts. v
red_bucket = 300
blue_bucket = 200
green_bucket = red_bucket + blue_bucket
fahrenheit = 32
celsius = 0
(F − 32) × 5/9 = C celsius = (fahrenheit - 32) * (5/9)
print("The answer is ", celsius)
Fahrenheit to Celsius
fahrenheit = 32
celsius = 0
(F − 32) × 5/9 = C celsius = (fahrenheit - 32) * (5/9)
print("The answer is %d" % celsius)
Fahrenheit to Celsius
fahrenheit = 32
celsius = 0
(F − 32) × 5/9 = C OFFSET = 32
celsius = (fahrenheit - OFFSET) * (5/9)
print("The answer is %d" % celsius)
Shopping Cart-Final Price
productCost = 100
Cost 100 TAX = 1.08
Tax 8% (1.08)
finalPrice = productCost * TAX
Final price is: print(finalPrice)
100 * 0.08 = $108.00
Shopping Cart-Final Price