CS1010S Programming Methodology
CS1010S Programming Methodology
Lecture 1
Introduction to CS1010S &
Python
15 Aug 2018
Welcome
Selamat
Hari Raya Haji
Makeup Lecture:
Mon 20 Aug, 6:30-8:30pm, UT-AUD2
3 things
WHY
should you
take CS1010S
WHAT
to expect in
CS1010S
HOW
to learn Python
(In 15 mins)
But first… The Cast
Dr Zhou Lifeng
Adi Yoga
Oana Barbu
Prof Ben
Leong
Samu
el
Jeffery Tutors
Chang
da
Marve
l
Keng
Hwee
Brya
n Yi
Wei
Jinyi
Enzi
o
Xia Rui
Sha
o
Yan
g
Ada
m Richard
Jonatha
n
Zhenyan
Ryan
Vincent
Yi Zhe
Jun
Ming
Nicholas
Jolene
Kaustub
h
Jen Han
Jessica
Ning
Yuan
Zhang
ChengYihui
Linh
Wulin
Kelvin Zi Liang
Sherry
Lan
Meng
Wang
Yu
Shu Yao
Tongyao
Justin
WHY
should you
take CS1010S
WHY
are you taking
CS1010S
1. Because I love programming.
2. Because I want to learn
programming.
3. Because I am interested in
computing.
4. Bo bian, core requirement.
WHY are you taking CS1010S?
Some Statistics
CORS
Round Quota Bidders Winning Bid
Round 1C (Returning) 81/88 90/89 156/1
Round 1C (New) 108/112 177/159 338/496
Round 2A 0/0 – –
Round 2B 0/0 – –
Round 3 0/0 – –
Class full
Quota taken up by preallocation
Round 1A (Returning) 90/100 8/12 1/1
% by Faculty
Science
71%
SoC
26%
Business
1%
Others
2% Warning!
There will be
Math!
By Seniority
Year 1, 70%
Year 2, 22%
Year 3, 6% Year 4, 2%
WHY you
should take
CS1010S
1. Because
computers are
useful
1. Because
computers are
useful
but they are dumb
They will precisely
execute every
instruction given,
even bad ones
Personal Computer
What will you use to
• Write a report?
• Do accounting?
• Statistical analysis?
• Find prime numbers?
• Solve a puzzle?
When is Cheryl’s Birthday?
What will you use to
• Write a report?
• Do accounting?
• Statistical analysis?
• Find prime numbers?
• Solve a puzzle?
• Scrape data from a website?
What will you use to
• Write a report?
• Do accounting?
• Statistical analysis?
• Find prime numbers?
• Solve a puzzle?
• Scrape data from a website?
Do cool stuff
“
Mill Jianprasert
NUS B.B.A
Management Associate, Garena
You wouldn’t believe what I have to
do for my first task (at work)…
Write some Python programme to
automate some data processing.
Hahahaha.
Who would have thought!
”
Help simplify
your work
2. Because pain is
good for you
Why should you take CS1010S
WHAT
to expect in
CS1010S
Work.
A lot of
work.
A lot of
hard work.
A lot of
hard work.
and some fun 🙂
Lectures
Here!
Recitations
Start next week
Tutorials
Start in week 3
Tutorial Balloting
Do NOT use CORS
Fill in preferences in Survey
Make sure no clashes!
Recitation will continue to be
balloted on CORS
Weekly Schedule
Classes Assignments
Mon
Tue
Lecture
Training
Wed Lecture
Tutorial
Training
Thu
Recitation
Fri
Sat
Sun
Mon
Tutorial
Tue
Important Dates
Wed 3 Oct: Midterm Test (6:30-8 pm)
Fri 19 Oct: Makeup Midterm (6:30 pm)
Sat 17 Nov: Practical Exam (12-6 pm)
Fri 23 Nov: Re-practical Exam (2 pm)
Please any schedule
early
Google Calendar
https://calendar.google.com/calendar/ical/0eqa645n5o9cc8t1idjjlludss%40
group.calendar.google.com/public/basic.ics
https://calendar.google.com/calendar/ical/0eqa645n5o9cc8t1idjjlludss@group.calendar.google.com/public/basic.ics
No textbook
Save money
The trick:
Consistency
The problem:
Staying
consistent is
HARD
gaming can make a
better world
– Jane McGonigal
17 Mar 2010
“
https://coursemology.org
7 Problem Sets
16 Main Missions
+ Side quests & Contests
+ 24/7 Grading
+ Unlock Achievements
+ Badges
+ Leaderboard
COMPLETE
MISSION
COMPLETE
MISSION
+XP
COMPLETE
MISSION
COMPLETE
SIDEQUESTS
+XP
COMPLETE
MISSION
COMPLETE
SIDEQUESTS
WIN CONTESTS
+XP
COMPLETE
MISSION
COMPLETE
SIDEQUESTS
WIN CONTESTS
ATTEND
TUTORIALS
+XP
COMPLETE
MISSION
COMPLETE
SIDEQUESTS
WIN CONTESTS
ATTEND
TUTORIALS
POST ON
FORUM
(Reflections)
+XP
ENOUGH XP?
LEVEL UP!
Lectures
Trainings
Finish by Friday
Recitations
Tutorials
+ Trainings
Missions
Side-quests
Contests
Forums
Exams
Assessment Overview
Coursemology 25%
Tutorial Participation 5%
Mid-term Exam 15%
Wed, 3 Oct, 6:30 – 8:00pm
Practical Exam 15%
Sat, 17 Nov, 12:00 – 6:00pm
Final Exam 40%
Tue, 27 Nov, 9:00 – 11:00am
The Theory of Aiming
PASS
The Theory of Aiming
PASS
Not to worry.
Help is always
available
Remedial
TBA
Email Us
cs1010s-staff@googlegroups.com
Discussion Forum
Do Subscribe
CS1010S Road Map
BASIC
INTERMEDIATE
ADVANCED
Procedural
Abstraction
Higher-Order
Procedures
Recursion
Iteration
Wishful
Thinking
Order of
Growth
Data
Abstraction
List
Processing
Multiple
Representations
Object-Oriented
Programming
Memoization
Dynamic
Programming
Mutation &
State
Fundamental concepts of computer programming
Searching & Sorting
Bust some Myths
Myth 1
“Not everyone can
learn to program”
Myth 1
“Not everyone can
learn to program
algebra”
Myth 2
“I have no
programming
experience. How to
survive?”
Michael Yong
Year 2
Google Intern
USD7k a month
Myth 3
“I’m a girl, how can
you expect me to
program?”
http://slatestarcodex.com/2017/08/07/contra-grant-on-
exaggerated-differences/
Myth 4
“The bell-curve will
save me.”
Grade-less
0
5
10
15
20
25
30
35
<20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100
2013 2014
0
5
10
15
20
25
30
35
<20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100
2013 2014
Myth 5
“No one will bother if I
copy my
friend/senior’s code.”
Caught plagiarizing
1. Zero marks for affected Mission
2. Removal of S/U privilege
*Seniors sharing code will be considered to be
abetting in plagiarism
Plagiarism
The act of presenting another’s
work or idea that as your own.
Plagiarism #1
Direct copying
.py .py
Plagiarism #2
“Referencing”
.py .py
.py
Plagiarism #3
“Discussion”
.py
.py
.py
Not Plagiarism
Discussion (the proper way)
.py
.py
.py.py
Not Plagiarism
Assistance
.py
.py
.py
3. Because coding
is the new literacy
Why should you take CS1010S
Well… not really
What are we teaching you?
What are you learning?
Python?
Not quite.
Python is just the tool
Critical Thinking
Problem Solving
Let's hear it
from your
seniors
many paths to
success
HOW
to learn Python
(In 15 mins)
IDLE
http://www.python.org
http://www.python.org/download/releases/3.4.2/
Python 2
vs
Python 3
Python 3.7.0
for CS1010S
Why Python
• Clear and readable syntax
• Intuitive
• Natural expression
• Powerful
• Popular & Relevant
Example: PayPal
• ASF XML Serialization
• C++ → 1580 lines
• Python → 130 lines
https://www.paypal-engineering.com/2014/12/10/10-
myths-of-enterprise-python/
Simplicity
Futile to Teach
a Language
Here today, gone tomorrow
Computational
Thinking
What is a program?
• A sequence of instructions
• That modifies some state (of the
computer)
What is a program?
Example:
1. Pick up the crate
2. Move 5 meters
3. Turn right
4. Move 5 meters
5. Put down the crate
What is the state
being modified?
Python program
a = 1
b = 2
c = a + b
if c < 0:
print('Yes')
else:
print('No')
Solve problems
• Suppose you have to program an
oven to bake bread
Idea
• Bake at 375°F for 30-35 minutes
or until golden brown and bread
sounds hollow when tapped.
Implementation?
1. Start timer
2. Measure temperature
3. If temp < 375°F then turn on heating
element
4. If temp > 375°F then turn off heating
element
5. If timer < 35 mins go back to step 2 Elements of Programming 1. Primitives • Numbers: 4 , 7/2 , 428.3 • Operators: + , - , * , / • Symbols: a , pi , foo 2. Means of Combination 5 + 3 ((5 + 3)-(2 * 3)) 8 2 3. Means of Abstraction 7 + 6 a = 3 a + 6 13 9 4. Controlling Logic If the light is red, stop. Else if it is amber, accelerate. Else, proceed with caution. While you are hungry, eat a spoonful of rice. Burp. Variables • Start with 'a'-'z' or 'A'-'Z' or '_' • Contain only alphanumeric characters or '_' • Case sensitive Ian_Lee != ian_lee Variables • Avoid reserved keywords e.g. if • Python convention: lower case letters separated by '_' •e.g. count_change • Store memory addresses Types int float bool str None 8 45 1234 2.3 3.14159 True False "cs1010s" 'cs1010s' Type(…) >>> type(123)
>>> type(‘123’)
>>> type(None)
Type conversion
>>> str(123)
‘123’
>>> float(‘45.2’)
45.2
>>> int(23.8)
23
>>> int(‘cs1010s’)
ValueError!
Assignment
>>> abc = 18
>>> my_string = ‘This is my string’
>>> x, y = 1, 2
variable address
abc id1
my_string id2
id1: int
18
id2: str
“This is my string”
x id3
y id4
id3: int
1
id4: int
2
Operators
Arithmetic:
>>> a = 2 * 3
>>> a
6
>>> 2 ** 3
8
+ – * / ** // %
Operators
Arithmetic:
>>> 11 / 3
3.6666666666666665
>>> 11 // 3
3
>>> 11 % 3
2
+ – * / ** // %
Truth Values
Statements can be either true or
false
2 > 1 is true
5 < 3 is false
Operators
Comparison:
>>> 1 <= 10
True
>>> 5 > 15
False
>>> 5 <= 5 True > >= < <= == != Operators Comparison: >>> 2 != 3
True
>>> ‘1’ == 1
False
>>> False == False
True
> >= < <= == != Operators Logic: >>> True or False
True
>>> True and False
False
>>> not False
True
or and not
Operators
Logic:
a or b True if either a or b is
True
a and b True if both a and b are
True
not a True if a is not True
or and not
Truth Tables
NOT
True False
False True
OR True False
True True True
False True False
AND True False
True True False
False False False
Truth Value Revisted
• Python has keywords True and
False
• In Python 3.x, True and False
will be equal to 1 and 0
• Anything that is not 0 or empty
will be evaluated as True
Operators
Logic:
>>> True and 0
0
>>> not ‘abc’
False
>>> 1 or 0
1
or and not
Strings
>>> s = ‘ba’
>>> t = ‘ck’
>>> s + t
‘back’
>>> t = s + ‘na’ * 2
>>> t
‘banana’
>>> ‘z’ in t
False
>>> ‘bananb’ > t
True
>>> ‘banan’ <= t
True
>>> ‘c’ < t
False
String Slicing
• A String is a sequence of characters
• We can index a string, i.e.
>>> s = ‘abcd’
>>> s[0]
‘a’
>>> s[2]
‘c’
• First character is 0
String Slicing
s[start:stop:step]
>>> s = ‘abcdef’
>>> s[0:2]
‘ab’
>>> s[1:2]
‘b’
>>> s[:2]
‘ab’
non-inclusive
>>> s[1:5:3]
‘be’
>>> s[::2]
‘ace’
Conditional
if
statement(s)
e.g.
>>> a = 3
>>> if a > 0:
print(‘Good’)
‘Good’
indentation
Conditional
if
statement(s)
else:
statement(s)
e.g.
>>> a = 3
>>> if a > 0:
print(‘yes’)
else:
print(‘no’)
‘yes’
Conditional
if
statement(s)
elif
statements(s)
else:
statement(s)
e.g.
>>> a = -3
>>> if a > 0:
print(‘yes’)
elif a == 0:
print(‘no’)
else:
print(‘huh’)
‘huh’
Conditional
if
statement(s)
elif
statements(s)
elif
statements(s)
else:
statement(s)
e.g.
>>> a = 4
>>> if a > 0:
print(‘yes’)
elif a == 0:
print(‘no’)
elif a == 4:
print(‘ahh’)
else:
print(‘huh’)
‘yes’
Conditional
while
statement(s)
>>> a = 0
>>> while a < 5: a = a + 1 print(a) 1 2 3 4 5 Python in 15 mins Am I now a programmer? What does it take to be a programmer? Do you know 1. your “ABC”? 2. how to form words? 3. how to write sentences? If you answered YES to all, surely you must be a poet What does it take to be a poet? What does it take to be a programmer? To be programmer 1. Know the elements of programming 2. Know the grammar of programs 3. Able to read and understand programs 4. Must write working programs This step is not trivial Learning Outcomes At the end of the course, you should be able to: • describe the output of a basic program • write a basic program to solve a given problem Practice Practice Practice Learning how to Learn Feeling Overwhelmed? Questions? Ways to earn XP Survey +100 XP before 21 Aug Training +100 XP By Friday + 50 XP otherwise See you next week.