0% found this document useful (0 votes)
59 views

TECH1200 Week 1 Workshop

Kaplan University: TECH1200 Week 1 Workshop
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views

TECH1200 Week 1 Workshop

Kaplan University: TECH1200 Week 1 Workshop
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

TECH1200

Fundamentals of
Programming
Lesson 1
Hello World!
COMMONWEALTH OF AUSTRALIA
Copyright Regulations 1969

WARNING

This material has been reproduced and communicated to you by or on behalf of


Kaplan Business School pursuant to Part VB of the Copyright Act 1968 (the Act).

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.

Do not remove this notice.


Subject Learning Outcomes
1 Interpret simple program
specifications.
2 Produce a high-level model via the use of
pseudocode and flow charts.
3 Transfer a high-level model into a
software application via the use of a
programming language.
4 Use an integrated development
environment to develop, debug and
test a solution written in a
programming language.
5 Use a programming language to read and
write data to a persistent storage.
Subject Description
This subject covers the fundamentals of software
design and introduces students to Python
programming language. This is complemented by
instruction on the construction of problem-solving
techniques via the use of flow charts and other
common methods among IT professionals such as
pseudocode. This subject also addresses the
principles and standard procedures associated
with the development and testing of algorithms
with an emphasis on the recommendation of
coding best practices.
Assessments
Assessment Learning Weighting Mode of Submission Details
outcomes Submission dates

Control Flow LO1, LO2, 20% MyKBS Week 5 Control Flow


Prototype LO3 Prototype to
produce
pseudocode and
flowchart

Online Tasks LO1, LO4 40% MyKBS Week 9 Solving and


Analysis analysing
programming tasks

Coding LO1, LO4, 40% MyKBS Week 13 Develop, debug,


Assignment LO5 and test a code
Analysis solution
Weekly Schedule
Topic

Week 1 Introduction to Python 3

Week 2 Control Flow

Week 3 Lists

Week 4 Loops

Week 5 Functions

Week 6 Revision Week

Week 7 Strings

Week 8 Modules

Week 9 Dictionaries

Week 10 Files

Week 11 Classes

Week 12 Revision Week and Summary


Subject Resources
• External Online Resources
• KBS Forum
• Applications:
– Microsoft Word
– Microsoft Visio
– PyCharm Community IDE
Welcome to Python!
• Python is the top programming language
on the TIOBE and PYPL Index.

Source: https://statisticstimes.com/tech/top-computer-languages.php
Python is friendly for beginners
• Python syntax is basic to understand, it’s an ideal language
for beginners, particularly with no or limited programming
experience
• Python is a general purpose language, and can be used in
various fields, such as but not limited to:
– Programming / Computer Science / Software Engineering
– Data Science
– Machine Learning
– Web Development
– Scripting Tools
– Applications and Analysis Tools
• Popular frameworks and libraries, like: TensorFlow, Numpy,
SciPy, Pandas, Theano, PyTorch, Keras, Matplotlib,
BeautifulSoup, OpenCV, and more than 100,000 others!
Python programming language
• Python, like other programming
languages, allows us to communicate
commands to a computer
• In this subject, we will use Python 3
• Our first program “Hello World!”
– Input commands
variable_name = "World"
print("Hello " + variable_name + "!")

– Python Output Hello World!


Print
• The print() function prints a message to
the console or output
– In this case, the message is a String
“Welcome to this subject :)”
print("Welcome to this subject :)")

– And, the output of the print() function is:


Welcome to this subject :)
Strings
• Strings must be surrounded by either:
– Single quotation marks ‘’
print('String with Single quotation marks')

– Double quotation marks “”

print("String with Double quotation marks")

• It does not matter which is used, but


ensure consistent usage
Variables
• Variables store a value
• Variables assign a value using an equals
sign =
– String message “This is the value” is stored in
a variable called variable_string
– Integer value of 100 is stored in a variable
called variable_integer
variable_string = "This is the value"
variable_integer = 100
Activity
What is the output of this code…?
variable = 100
variable = "This is the value"
print(variable)

Answer:
This is the value

Reason:
• The stored value in variable can be
changed after it has been set
Comments
• Comments start with a #
1. Comments can be at the start of a line
# Our first program to print "Hello World!"
variable_name = "World"
print("Hello " + variable_name + "!")

2. Comments can be at the end of a line


variable_name = "World" # Change "variable_name" to your name
print("Hello " + variable_name + "!")

3. Comments can ignore a whole line of code


#variable_name = "World"
#print("Hello " + variable_name + "!")
print("The above two lines are ignored by Python.")
Errors
• We will make errors… But, how does the
program communicate this to us?
– PyCharm or any other Integrated
Development Environment (IDE) will:
• Display the error type
• Information where the error has occurred
• Two common error types in Python:
– SyntaxError
– NameError
SyntaxError
• SyntaxError is produced when we did not
adhere to the Python syntax
– Let’s attempt this code…
some_variable = "VALUE'

– PyCharm console displays the following error:


some_variable = "VALUE'
^
SyntaxError: unterminated string literal (detected at line 1)
– Solution: in this case, some_variable variable,
must have consistent String usage. Both double
quotes or both single quotes, not one of each.
some_variable = "VALUE"
NameError
• NameError is produced when we did not
define a variable
– Let’s attempt this code…
print(some_variable)

– PyCharm console displays the following error:


print(some_variable)
NameError: name 'some_variable' is not defined

– Solution: some_variable variable must be


defined and a value must be assigned to the
variable, before the print() function statement
some_variable = "VALUE"
print(some_variable)
Activity
• What error(s) do you get with this code:
numerator = 777
denominator = 0
result = numerator / denominator
print(result)

Answer:
• ZeroDivisionError – occurs when a
number (denominator) is divided by a 0 or
0.0 result = numerator / denominator
ZeroDivisionError: division by zero
Numbers
• There are three numeric types:
1. int
• Integer or int, must be a whole number, it can be 0,
positive or negative, but must be without decimals
2. float
• “Floating point number” or float, is a number, it can be
positive or negative, but must contain one or more
decimals
3. complex
• Complex numbers assign a “j” to the variable value as
the imaginary part. For this subject, you will not use
this numeric type
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: variable a: <class 'int'>


variable b: <class 'float'>
variable c: <class 'int'>
variable d: <class 'str'>
variable e: <class 'int'>
variable f: <class 'float'>
variable g: <class 'float'>
Bonus function: type()
• If you are not sure what the type of
variable it is, use the type() function
• In the previous Activity, let’s use variable d
as an example:
d = "678"
print(type(d))

• If you said variable d is a number or


Integer or int… Well, it’s a String or str
type:
<class 'str'>
Calculations
• Python can compute math questions
– Addition with a plus sign +
print(69 + 5)

– Subtraction with a minus sign –


print(6 - 87)

– Multiplication with an asterisk *


print(6.2 * 100)

– Division with a slash /


print(3 / 37)
Exponents
• Python can compute exponentiation with a
double asterisk **
# 2 to the 12th power, 2^12, or 4096
# or... 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2
print(2 ** 12)

# 6 squared, 6^2, or 36
print(6 ** 2)

# 2 to the half power, 2^0.5, or 1.41


print(2 ** 0.5)
Modulo
• Python can compute modulo operation
with a percent sign %, which returns the
remainder of the division operation
# Prints 3
# 23 / 5 is 4, with a remainder of 3
print(23 % 5)

# 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)

• However, you cannot concatenate a str type with an int


type
# prints TypeError: can only concatenate str (not "int") to str
a = "Hello"
b = 5
print(a + b)
Plus Equals
• A shortcut to update a variable value can
be done by using the plus equals sign +=
# prints 105
distance = 100
distance += 5 # same as distance = distance + 5
print(distance)

# prints add words to the String added


message = "add words to the String"
message += " added" # same as message = message + " added"
print(message)
Multi Line Strings
• Strings can be assigned multiline values by
using three double or single quotes at the
start and end of variable assignment
variable = """
I can
I can
write
write
here Output
here
or here
or here
:O
:O
"""
print(variable)

• Notice the empty line in the first and last line


Subject recommendations and
expectations
• Attempt Week 1 Workbook – Fairy Fragrances
– It will give you some indication as to how you might
be progressing after Week 1
• Review Week 1 Summary document
– For future Workshop Weeks, students should create
their own Workshop Week Summary
• Regularly practice after each Workshop
– Students are expected to create and evaluate other
problems that they make up or find
• Trying to complete the assessments few days
before the due date is a recipe for disaster

You might also like