Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
37 views34 pages

0 - ISOM2007 Getting Started 2024 Fall

Uploaded by

daphne1747
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views34 pages

0 - ISOM2007 Getting Started 2024 Fall

Uploaded by

daphne1747
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 34

ISOM2007 – All Sections

Programming for Business


Analytics
Getting Started

Hongchuan Shen
Faculty of Business Administration
University of Macau
E22-1061, x4175, [email protected]
Acknowledge: Philip Pun and Rebecca Lao

1
Learning Goals
In this lecture, you will learn:
Computer hardware
Algorithms
How to use pseudocode to describe an algorithm
Print “Hello World!”
How to diagnose and fix programming errors
Programming habit

2
Hardware
• Hardware consists of the physical elements in a computer
system.
• Some very visible examples are the monitor, the mouse, external
storage, and the keyboard.
• The central processing unit (CPU) performs program control
and data processing
• Storage devices include memory (RAM) and secondary storage
• Hard disk
• Flash drives
• CD/DVD drives
• Input / output devices allow the user to interact with the
computer
• Mouse, keyboard, printer, screen…

3
Memory
• A simple way to envision primary memory is a table of cells all the
same size, one byte, and each containing a unique address
beginning with 0.
• The “typical” computer has a main memory ranging from 4 gigabytes
(GB) to 32 GB.
• How big is a gigabyte?
• A byte is 8 bits.
• A kilobyte (KB) is 210 = 1024 bytes, or “about 1 thousand bytes.”
• A megabyte (MB) is 220 = 1,048,576 bytes, or “about 1 million bytes.”
• A gigabyte (GB) is 230 = 1,073,741,824 bytes or “about 1 billion bytes.”
• Follow the same logic for terabyte (TB), petabyte (PB), Exabyte (EB),
Zettabyte (ZB), Yottabyte (YB) etc.

10/18/2024 4
Computer Configurations

5
Algorithms
• An Algorithm is:
• a sequence (the order mattering) of actions to take to
accomplish the given task
• An algorithm is like a recipe; it is a set of instructions
written in a sequence that achieves a goal
• For complex problems software developers write an
algorithm before they attempt to write a computer
program

6
Algorithms
• Algorithms are simply plans
• Detailed plans that describe the steps to solve a specific
problem
• You already know quite a few
• Calculate the area of a circle
• Find the length of the hypotenuse of a triangle

7
A Simple Example
• A simple algorithm to get yourself a drink of orange
juice
• For simplicity, the following are true:
• You have a clean glass in the cabinet
• You have orange juice in your refrigerator
• So one valid algorithm is:
1. get a glass from your cabinet
2. go to the refrigerator and get the orange juice container
3. open the orange juice container
4. pour the orange juice from the container into the glass
5. put the orange juice container back in the refrigerator
6. drink your juice
8
Pseudo-Codes
• Pseudocode
• Textual representation of an algorithm similar to everyday
English
• Not actually executed on computers
• Helps us “think out” a program before writing it
• Easy to convert into a corresponding computer program
• Consists only of executable statements
• Type pseudocode in to your source code as comments, then fill
in the actual code

9
Pseudo-Code: Example
• Pseudocode Example:
get the exam scores
average the exam scores
if the average is greater than or equal to 60 print “Passed”
otherwise print “Failed”

• Translates to Python:
# get the exam scores
exam1 = 60
exam2 = 80
exam3 = 75
# average the exam scores
score = exam1 * 0.3 + exam2 * 0.3 + exam3 * 0.4
# conditions and outputs
if (score >= 60):
print(“Passed”)
else:
print(“Failed”)
10
Flowcharts
• Flowchart
• Graphical representation of an algorithm
• Drawn using certain special-purpose symbols connected by arrows called flow-
lines
• Rectangle symbol (action symbol):
• Indicates any type of action
• Oval symbol:
• Indicates the beginning or end of a program or a section of code
• Diamond symbol (decision symbol)
• Indicates decision is to be made
• Contains an expression that can be true or false
• Test the condition, follow appropriate path

11
Flowchart Symbols &
Example
Start

Get exam
scores

Average the
exam scores

false
Average ≥ 60

true

Print “Passed”

End

12
IDE for Python Program
Development
• IDE stands for Integrated Development Environment,
is a software application that provides
comprehensive facilities to computer programmers
for software development.
• 5 Popular Python Open-Source IDEs for data science
partitioners:
• Jupyter
• PyCharm
• Atom
• Spyder
• Visual Studio Code
13
Install Python on Your
Computer
 To install Python 3, go to
https://www.python.org/download/
 Follow the direction for the latest version
 If more than one versions are offered, make sure to
choose the one that starts with the number 3 (e.g.
Python 3.8.5), not 2 (e.g. Python 2.7.12)

14
Install Python on Your
Computer

15
Install Jupyter Notebook

• Using the following installation steps (for Windows


& Mac):
Download Anaconda. Recommended downloading Anaconda’
latest Python 3 version (currently Python 3.5 or higher)
(https://docs.anaconda.com/anaconda/navigator/install/)
Launch Anaconda Navigator
Click on the Install Jupyter Notebook Button
Beginning the installation
Loading Packages as instructed
Finished Installation

16
Install Jupyter Notebook

17
Jupyter Notebook
Environment

18
Use UM Virtual Computer
Room
• UM Virtual Computer Room is another option to
develop your Python program
• You need to first install the following on your device
• Pulse Secure
• VMware Horizon Client
• For the details, please visit
• Virtual Computer Room
• How to access Virtual Computer Room from Windows V
Mware Horizon Client?
• How to access Virtual Computer Room from Mac VMwar
e Horizon Client?
19
Use UM Virtual Computer
Room
• If you are OFF CAMPUS, you need this

20
Use UM Virtual Computer
Room
• Invoke the VMware Horizon Client

21
Use UM Virtual Computer
Room

22
Use UM Virtual Computer
Room

23
“Hello World”

• Type the following into the Editor:


# My first Python program
print(“Hello World!”)
• Remember – Python is case sensitive
• You have to enter the upper and lower case letters
exactly as this appear above

24
Analyzing Your First Program
• A Python program contains one or more lines of instructions
(statements) that will be translated and executed by the
interpreter
# My first Python program
Print(“Hello World!”)
• The first line is a comment (a statement that provides
descriptive information about the program to
programmers).
• The second line contains a statement that prints a line of
text onscreen “Hello, World!”

25
Basic Python Syntax: Print
• Using the Python ‘print()’ function.
• A function is a collection of programming instructions that carry
out a particular task (in this case to print a value onscreen).
• It’s code that somebody else wrote for you!

26
Syntax for Python Functions

• To use, or call, a function in Python you need to


specify:
• The name of the function that you want to use (in the
previous example the name was print)
• Any values (arguments) needed by the function to carry
out its task (in this case, “Hello World!”).
• Arguments are enclosed in parentheses and multiple
arguments are separated with commas.
• A sequence of characters enclosed in quotations marks
are called a string

27
More Examples of the print
Function
• Printing numerical values
• print(3 + 4)
• Evaluates the expression 3 + 4 and displays 7
• Passing multiple values to the function
• print(“the answer is”, 6 * 7)
• Displays the answer is 42
• Each value passed to the function is displayed, one after another, with a blank space
after each value
• By default the print function starts a new line after its arguments are printed
• print(“Hello”)
• print(“World!”)
Hello
World!

28
Errors
• There are two Categories of Errors:
• Compile-time Errors
• aka Syntax Errors
• Spelling, capitalization, punctuation
• Ordering of statements, matching of parenthesis, quotes…
• No executable program is created by the compiler
• Correct first error listed, then compile again.
• Repeat until all errors are fixed
• Run-time Errors
• aka Logic Errors
• The program runs, but produces unintended results, Non-fatal Bugs (Using =
instead of == in an if statement)
• The program may “crash”, Fatal Bugs (Divide by zero)

29
Syntax Errors

• Syntax error are caught by the compiler


• What happens if you
• Miss-capitalize a word: Print("Hello
World!")
• Leave out quotes print(Hello World!)
• Mismatch quotes print("Hello World!')
• Don’t match brackets print('Hello’
• Try yourself after class

30
Logic Errors

• What happens if you


• Divide by zero print(1/0)
• Misspell output print("Hello, Word!")
• Forget to output Remove line 2
• Programs will compile and run
• The output may not be as expected
• Type each example above in the Python IDE
• What error messages are generated?

31
Avoiding Bugs
• Don’t ignore compiler warnings
• Most warnings are bugs
• Your code should compile without any warnings

• Don’t write your code all at once


• Writing code isn’t like writing a term paper. Don’t type in a complete “rough draft”
of your code
• Write a few lines of code, then compile and test it
• When you do find a bug, you know it must be caused by the code you wrote since
your last test

• Use good programming style


• Organize your code well to help find bugs quickly
• Use comments to identify what code is supposed to do
• Give variables names that describe how they are used

32
Elements of Style
• Comments
• Use comments to describe what is supposed to happen
• Compare comments to code to find bugs

• Naming Conventions
• Don’t use one letter variable names
• Use names that describe purpose
• Be consistent in how you choose names

• White-space
• The compiler ignores spaces, carriage returns and tabs
• Use carriage returns to separate code which serves a new purpose
• Use indentation to indicate the flow of control

33
Indentation
Example: Example:
if exam: if exam:
if (score >= 50): if (score >= 50):
print (“Passed \n”) print (“Passed \n”)
else: else:
print (“Failed \n”) print (“Failed \n”)

Example: Example:
if exam: if exam:
if (score >= 50): if (score >= 50):
print (“Passed \n”) print (“Passed \n”)
else: else:
print (“Absent \n)” print (“Absent \n”)

34

You might also like