CS1010S+Lecture+01+ +introduction
CS1010S+Lecture+01+ +introduction
Methodology
Lecture 1
Introduction to CS1010S & Python
11 Aug 2021
Welcome
3 things
WHY
should you take
CS1010S
WHAT
to expect in CS1010S
HOW
to learn Python
(In 15 mins)
But first… The Cast
Prof Ben Leong
(Jedi Advisor)
Dr. Ashish Deepak
Dr. Daren Ler
Tutors
Tze Lynn Uyen Vishandi Yong Zifeng Chris
Ryan Soo Yen Toh Yi An Lam
CS1010S
WHY are you taking CS1010S?
• Because I love programming.
• Because I want to learn programming.
• Because I am interested in computing.
• Bo bian, core requirement.
Business Others Warning!
FASS 2% 1%
2%
There will be
Math!
School of Faculty of
Computing Science
40% 55%
Year 3 Year 4+
Year 2 2% 3%
7%
Year 1
88%
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
https://youtu.be/H3q5S9PCoJA?t=109
Computers only do what you
say
They do not do what you
mean
“Take the bag of potatoes, peel half of
them and put them in a pot to boil”
What is a “Computer”?
The First Computers
Modern Computer
What will you use to
• Write a report?
• Do accounting?
• Statistical analysis?
• 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
CS1010S vs COS2000
Programming Methodology Computational Thinking for
Scientists
Computational Biology Life Science
Data Science Analytics Physics
Math, Applied Math, QF
Pharmacy
Statistics
Chemistry
Belongs to a family of Food Science
CS1101S, CS1010, CS1010E,
etc.
CS1010S vs COS2000
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
15 Main Missions
+ Side quests & Contests
+ 24/7 Grading
+ Unlock Achievements
+ Badges
+ Leaderboard
COMPLETE
+XP
MISSION
COMPLETE
+XP
MISSION
COMPLETE
SIDEQUESTS
COMPLETE
+XP WIN CONTESTS
MISSION
COMPLETE
SIDEQUESTS
COMPLETE
+XP WIN CONTESTS
MISSION
ATTEND
COMPLETE TUTORIALS
SIDEQUESTS
COMPLETE
+XP 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
AFAST Pilot
Alternative Final Assessment Timeline
The Theory of Aiming
PASS
The Theory of Aiming
PASS
Not to worry.
Help is always
available
Remedial
TBA
Technical Issues?
Email Us
[email protected]
Need Help?
Discussion Forum
Do Subscribe
CS1010S Road Map
Exceptions Data Visualisation
Memoization ADVANCED
Searching & Sorting Object-Oriented
Dynamic
Programming Programming
INTERMEDIATE
Higher-Order Multiple
List Dictionary
Procedures Representations
Processing
BASIC
Functional 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/
Past Semesters
No statistical difference
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
Academic Honesty Policy
• Not allowed
- receive any part of a solution to assignments
prior to submitting your own
- provide any part of a solution to a classmate
when it is they, and not you, who has not
solved it
Academic Honesty Policy
• Allowed
- showing erroneous code you have written to a
friend for help to identify the error
- help a classmate identify, but not fix, the error
in their code, after you have submitted your
assignment
- group discussion of assignments without
producing a solution for reference
David J. Malan, Brian Yu, and Doug Lloyd. 2020. Teaching Academic Honesty in CS50. In The 51st ACM Technical Symposium on Computer
Science Education (SIGCSE ’20), March 11–14, 2020, Portland, OR, USA. ACM, New York, NY, USA, 7 pages.
Why should you take CS1010S
1. Because computers are useful
2. Because pain is good for you
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
Programming Methodology
Foundations of
programming
HOW
to learn Python
(In 15 mins)
IDLE
http://www.python.org
Python 2
vs
Python 3
Python 3.9.x
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?
Do you know
1. how to read?
2. how to form words?
3. how to write sentences?
Training +100 XP
No deadline for
Lecture 1
See you next week