TECH1200 Week 1 Workshop
TECH1200 Week 1 Workshop
Fundamentals of
Programming
Lesson 1
Variables
COMMONWEALTH OF AUSTRALIA
Copyright Regulations 1969
WARNING
The material in this communication may be subject to copyright under the Act. Any
further reproduction or communication of this material by you may be the subject of
copyright protection under the Act.
Week 1 Variables
Week 3 Lists
Week 4 Loops
Week 5 Functions
Week 7 Strings
Week 8 Modules
Week 9 Dictionaries
Week 11 Classes
country = "Japan"
print("Tokyo is the capital city of " + country)
Reason:
• The stored value in variable can be
changed after it has been set due to line-by-
line execution.
Data Types (1/3)
The following data types are used in Python for storing
values in variables:
• Integers: numeric values without decimal points ( int )
• Floats: numeric values with decimal points ( float )
• Strings: text values composed as sequence of
characters ( str )
• List: ordered collection of multiple mutable values (
list )
• Tuple: ordered collection of multiple immutable values
( tuple )
• Boolean: True and False values ( bool )
Data Types (2/3)
Below are examples of data types being used
in variables:
name = "Michael"
age = 24
print(type(name))
print(type(age))
Activity
• For each of the variables, what type of
variable is it? a = 0
b = 42.1
c = -912
d = "678"
e = 13513517
f = 0.0
g = -13.012
Answer:
• ZeroDivisionError – occurs when a
number (denominator) is divided by a 0 or
0.0 result = numerator / denominator
ZeroDivisionError: division by zero
Calculations
• Python can compute math questions
– Addition with a plus sign +
print(69 + 5)
# 6 squared, 6^2, or 36
print(6 ** 2)
# Prints 1
# Important Note for "Modulo % 2"
# Returns "0 for even numbers" and "1 for odd numbers"
print(21 % 2)
# Prints 4
# 4 / 8 is 0, with a remainder of 4
print(4 % 8)
Concatenation
• The plus sign + can add two str types or Strings (and
not just numeric types)
# prints "HelloWorld!"
a = "Hello"
b = "World!"
c = a + b
print(c)