Slides WK1
Slides WK1
Introduction to Business
Programming in Python
1
Instruction team
David Xu (S01) Teaching Assistants
Office hours: By appointment LAU Man Kit: [email protected]
Office: LAU-6-246 HUO Xuenan: [email protected]
Tel: 3442 8530 XIAN Chunyi: [email protected]
Email: [email protected] SHI Zhuzhi: [email protected]
2
About Me
• Assistant Professor at the Department of Information Systems
• Background
• Undergraduate in Supply Chain Management
• PhD in Information Systems
3
Class goals
• Understand the basics of Python.
4
Course overview
• It is easy to learn and fun to use Python.
5
Course overview
• Python is a popular open source programming language
widely used by business professionals to develop
applications in big data, artificial intelligence, financial
technology, and so on.
6
Key topics of CB2240
• Basics:
• Numbers, strings, list, tuples.
• if statements, for and while loops, functions, etc.
• Applications
• Data handling, data visualization, etc.
7
Module Topic Reading
1 Introduction Overview Chapter 1
2 Core objects Numbers 2.1
3 Strings 2.2
Schedule
8
Module Topic Reading
1 Introduction Overview Chapter 1
2 Core objects Numbers 2.1
3 Strings 2.2
4 Lists and tuples 2.4
Schedule
(S01, S03)
9
Advanced classes
• IS3240 Advanced Python (sample topics: NumPy, Pandas, matplotlib).
10
Weekly routine
• Lecture (≈1 hour)
• Quiz (10 minutes)
• Basic concepts and examples
• Lab (≈ 2 hours)
• Examples
• Classwork
• Homework
• Take-home
11
Assessment
• Class Participation: 5%
• Piazza Participation: 5%
• Classwork: 10%
• Homework: 20%
• Quizzes: 20%
• Final Exam: 40%
• For the weekly class participation, classwork, homework, and quizzes, the top 10
out of 13 scores in each category will count toward the final grade.
12
Weekly classwork & homework
• Deadlines:
• 4:00 pm on Thursday in the week (S02)
• 4:00 pm on Monday in the following week (S01, S03)
13
Piazza interface
14
Piazza participation
• Post all Python questions on Piazza (NOT via emails). Q&A on Piazza (accessible
via Canvas) will count towards the participation score.
• Your questions will be valuable to your classmates.
• Answering questions will help others and yourselves.
• You can post anonymously (your classmate can’t see your name, instructors still
can).
15
Communication policy
• If you have questions about class logistics, feel free to email us.
• All Python questions should be posted on Piazza.
• What the instructor & TAs won’t do: debug programs for you.
• You can post error messages on Piazza.
16
8
• Be consistent
• Be engaging
18
Weekly quiz on Canvas
• Weekly quizzes will test your knowledge about content
from the previous week.
• Review before coming to class.
19
Lecture 1.
An Introduction to Computing
and Problem Solving
20
Why programming?
• Programming allows us to
21
Why programming?
• Today, almost every profession needs programming to
some extent.
https://www.youtube.com/watch?v=Dv7gLpW91DM
22
Real world application example
• Walmart and Amazon scrape each other’s product data.
23
Why Python?
• Large and still growing
Python community
24
Why Python?
• Powerful, multi-purpose
• Accounting
• Finance (e.g. quant, trader)
• Digital marketing
• Supply chain analytics
• Academic research
• Etc.
25
Why Python?
• Beginner-friendly
• Plain English
• Python
26
About Python
• Python is named after the British comedy group Monty Python.
27
A simple program
• What is an example of a program?
28
Problem Solving
18 23 53 08
29
Problem Solving
• (Step 1) Write down the first number on a
piece of paper (largest so far and is the
largest if it is the only number)
• (Step 2) Repeat the following steps until no
more numbers:
• (a) Take the next number from the list
• (b) Compare the two numbers, if the new
number is bigger it replace the old number on
the paper
• (c) Return to the first step
• After step 2, the last number of the paper is
the answer.
30
The problem-solving process
31
Questions and Answers
• Where will new programs be saved?
• Create a special folder to hold your programs
• Where can I research questions I have about Python?
• Documentation at https://www.python.org/doc/
• W3schools https://www.w3schools.com/python/
32
Program Planning and Tools
33
Program Planning
1. Analyze: Define the problem.
2. Design: Plan the solution to the problem.
3. Code: Translate the algorithm into a programming
language.
4. Test and correct: Locate and remove any errors in the
program.
5. Complete the documentation: Organize all the material
that describes the program.
34
Algorithm Development
Algorithm to determine the number of stamps for a letter
35
Problem Solving for Stamps
36
Think before you code
• Flowcharts
• Pseudocode
• Hierarchy charts
37
Flowcharts
38
Example
Flowchart
39
Pseudocode
• Abbreviated plain English version of actual computer code
40
Example Pseudocode
41
Hierarchy Chart
• Shows the overall program structure
42
Example Hierarchy Chart
43
Three structures
• Sequence structure
• Decision structure
• Repetition/loop structure
44
Sequence structure
• The postage-stamp problem has a sequence structure:
• Moved from one line to the next without skipping any lines.
45
Decision Structure
46
Direction of Numbered
NYC Streets Algorithm
• Problem: Given the street number of a one-
way street in New York City, decide the
direction of street - eastbound or westbound.
• In NYC
• Even-numbered streets: eastbound
• Odd-numbered streets: westbound
47
Direction of Numbered NYC Streets
Algorithm
• Input: Street number.
48
Street Direction Algorithm
49
Street Direction Algorithm
50
Street Direction Algorithm
51
Repetition Structure
• A programming structure that executes instructions many times.
• Need a test (or condition) to tell when the loop should end
• Check condition before each pass through loop
52
Repetition Structure
Are
you
single
?
While you are single
Look for a partner
Look for a
partner
54
Class Average Algorithm
• Problem: Calculate and report the average grade for a class.
55
Class Average Algorithm
• Input: Student grades.
• Processing: Find the sum of the grades;
count the number of students; calculate
average grade = sum of grades / number of
students.
• Output: Average grade
56
Class Average
Algorithm
57
Class Average Algorithm
59
Kahoot
Classroom projector Student laptop/cellphone
60
Kahoot
• Go to https://kahoot.it/
61
Lab 1
62
Objectives
• Install python
63
Python installation
• Install Python
• https://www.python.org/downloads/
• Versions:
• Some operating systems come with earlier versions of Python by default.
• All material in this class will be based on Python 3.12.1.
64
Open IDLE
• After installation, open IDLE.
• IDLE stands for Integrated DeveLopment Environment
65
Hello World!
66
The print function
67
Good programming practices
• There are a number of symbols in programming languages which
work in pairs, e.g., parentheses () and quotations marks “”.
68
The Zen of Python, by Tim Peters
69
Editor
70
Save program
71
Run program output
72
Documentation
• Document what you did in your
program so that it will be more
understandable by other people
or by yourself in the future.
73
The input function
74
Errors
• Don’t panic.
75
Show line numbers
76
Remember to submit Classwork 1 and Homework 1.
Review for Quiz 2.
77