CS1010S Lecture 01 - Introduction
CS1010S Lecture 01 - Introduction
Lecture 1
Introduction to CS1010S &
Python
17 Jan 2018
Welcome
3 things
WHY
should you
take CS1010S
WHAT
to expect in
CS1010S
HOW
to learn Python
(In 15 mins)
But first… The Cast
Adi Yoga
Mohammed
Haroon
Prof Ben
Leong
Tutors
Keng Jinyi
Jeffery Hwee Lek Peng Changda
Ana Leran
Marvel
Bryan
Chen
Kuang Jit Wu
Zhi Samuel
Jiang Yi Wei
Trevor Sean
Kuang
Shao
Timothy Enzio
Yingxu Ryan
Timothy Kian Yong
Hwee He
WHY
should you
take CS1010S
WHY
are you taking
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.
Some Statistics
CORS
Round Quota Bidders Winning Bid
Round 1A (Freshmen) 274 85 1
Round 1A 56 33 1
Round 2A (Minor) 209 0 0
Round 2B 209 104 1
Round 3A 113 165 800
Round 3B 3 16 2000
% by Faculty
Warning!
Others There will be
18% Math!
Arts
11%
Science
BBA
61%
10%
By Seniority
NG, 3%
Year 4, 17%
Year 1, 38%
Year 3, 17%
Year 2, 25%
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?
• Do accounting?
• Statistical analysis?
”
Hahahaha.
Who would have thought!
Mill Jianprasert
NUS B.B.A
Management Associate, Garena
Help simplify
your work
Why should you take CS1010S
2. Because pain is
good for you
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 Bidding
https://calendar.google.com/calendar/ical/0eqa645n5o9cc8t1idjjlludss%40
group.calendar.google.com/public/basic.ics
No textbook
Save money
The trick:
Consistency
The problem:
Staying
consistent is
HARD
“better world
gaming can make a
- 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
+XP
COMPLETE
MISSION
+XP
COMPLETE
MISSION
COMPLETE
SIDEQUESTS
+XP
COMPLETE WIN CONTESTS
MISSION
COMPLETE
SIDEQUESTS
+XP
COMPLETE WIN CONTESTS
MISSION
ATTEND
COMPLETE TUTORIALS
SIDEQUESTS
+XP
COMPLETE WIN CONTESTS
MISSION
ATTEND
COMPLETE TUTORIALS
SIDEQUESTS
POST ON
FORUM
(Reflections)
ENOUGH XP?
LEVEL UP!
Lectures
Trainings
Exams Finish by Friday
Forums Recitations
Side-quests Tutorials
+ Trainings
Contests
Missions
Assessment Overview
Coursemology 25%
Tutorial Participation 5%
Mid-term Exam 15%
Wed, 7 Mar, 12:00 – 1:30pm
Practical Exam 15%
Sat, 21 Apr, 12:00 – 6:00pm
Final Exam 40%
Mon, 7 May, 5:00 – 7:00pm
The Theory of Aiming
PASS
The Theory of Aiming
PASS
Not to worry.
Help is always
available
Remedial
TBA
Email Us
[email protected]
Discussion Forum
Do Subscribe
CS1010S Road Map
Memoization Searching & Sorting
ADVANCED
Dynamic Object-Oriented
Programming Programming
INTERMEDIATE
Higher-Order List Multiple
Procedures Processing Representations
BASIC
Procedural Data
Iteration Mutation &
Abstraction Abstraction
State
Wishful Recursion
Order of
Thinking Growth
Fundamental concepts of computer programming
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
35
30
25
20
15
10
0
<20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100
2013 2014
35
30
25
20
15
10
0
<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
.py .py
Plagiarism #2
“Referencing”
.py
.py .py
Plagiarism #3
“Discussion”
.py
.py
.py
Not Plagiarism
Discussion (the proper way)
.py
.py
Why should you take CS1010S
3. Because coding
is the new literacy
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
Python 2
vs
Python 3
Python 3.6.4
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 8
((5 + 3)-(2 * 3)) 2
3. Means of
Abstraction
7 + 6 13
a = 3
a + 6 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 8 45 1234
float 2.3 3.14159
bool True False
str "cs1010s"
'cs1010s'
None
Type(…)
>>> type(123)
<class 'int'>
>>> type('123')
<class 'str'>
>>> type(None)
<class '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
id1: int
variable address 18
abc id1 id2: str
“This is my string”
my_string id2
id3: int
x id3 1
y id4 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: or and not
>>> True or False
True
>>> True and False
False
>>> not False
True
Operators
Logic: or and not
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
Truth Tables
OR True False AND True False
True True True True True False
False True False False False False
NOT
True False
False True
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: or and not
>>> True and 0
0
>>> not 'abc'
False
>>> 1 or 0
1
Strings
>>> s = 'ba' >>> 'z' in t
>>> t = 'ck' False
>>> s + t
>>> 'bananb' > t
'back'
True
>>> t = s + 'na' * 2
>>> 'banan' <= t
>>> t
True
'banana'
>>> '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]
non-inclusive
>>> s = 'abcdef'
>>> s[0:2] >>> s[1:5:3]
'ab' 'be'
>>> s[1:2] >>> s[::2]
'b' 'ace'
>>> s[:2]
'ab'
Conditional
if <expr>:
statement(s)
e.g.
>>> a = 3
>>> if a > 0:
indentation
print('Good')
'Good'
Conditional
if <expr>: e.g.
statement(s) >>> a = 3
else: >>> if a > 0:
statement(s) print('yes')
else:
print('no')
'yes'
Conditional
if <expr>: e.g.
statement(s) >>> a = -3
elif <expr>: >>> if a > 0:
statements(s) print('yes')
elif a == 0:
else:
print('no')
statement(s)
else:
print('huh')
'huh'
Conditional
if <expr>: e.g.
>>> a = 4
statement(s)
>>> if a > 0:
elif <expr>: print('yes')
statements(s) elif a == 0:
elif <expr>: print('no')
elif a == 4:
statements(s) print('ahh')
else: else:
statement(s) print('huh')
'yes'
Conditional
while <expr>: >>> a = 0
statement(s) >>> 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?
Question: Do you know
• the elements of English? Yes
• the syntax of English grammar? Yes
• how to read sentences? Yes
• how to write meaningful Yes
sentences?
In that case are you a poet?
Do you know
1. the “ABCs”?
2. how to form words?
3. how to write sentences?