01C Programming Part 1
01C Programming Part 1
2022/23 Term 2
SMU Classification: Restricted
Road Map
Wk 10-13
Group Project
SMU Classification: Restricted
Labs – Compulsory
You are given 5 take-home labs to prepare you for the group project:
– Labs are mandatory – you must submit a working solution to eLearn
– Timely completion of your labs contributes to your class part score
Programming-related Assessment
Reference
• "Explorations in Computing" by John S. Conery (JSC)
– Publisher: Taylor & Francis CRC Press
– Homepage: http://ix.cs.uoregon.edu/~conery/eic/python/index.html
– PDF: ftp://ftp.cs.uoregon.edu/pub/conery/freeman/EiC.Mar.27.pdf
– The programming lessons for weeks 1 and 2 follow chapters 2 (Python Workbench) and 3
(Sieve of Eratosthenes) closely.
– Remaining lessons of this course will not be based on this textbook, but it's still an easy
introductory read for some of the topics that will be covered.
– JSC uses an IDE (Integrated Development Environment) such as IDLE for its "Tutorial
Projects", but we will use Colab instead.
SMU Classification: Restricted
Learning Outcomes
• By the end of this session, you should:
– Be familiar with
• (i) arithmetric operators (+, -, *, /)
• (ii) variables,
• (iii) integers & floats,
• (iv) using functions (such as sqrt),
• (v) Using Colab
SMU Classification: Restricted
– Go to
https://colab.research.google.com/drive/1cqEOlPw-18KvqHaMs66YS
YqIrUh9CkY3
– Textbook:
ftp://ftp.cs.uoregon.edu/pub/conery/freeman/EiC.Mar.27.pdf
SMU Classification: Restricted
operators
• Other useful operators:
% (mod, or remainder)
** (exponentiation)
SMU Classification: Restricted
• T15 requires you to "import sqrt", before using the sqrt() function. Try to call sqrt()
without first importing sqrt() and see what happens.
– You need to import the necessary module that a particular function is in before calling that function.
SMU Classification: Restricted
Function
Input(s) Something happens here Output
sqrt()
25 Something happens here 5.0
Variables
• Variables are temp “storage areas” for a value. You use an assignment statement to
store a value into a variable.
• Use the = operator to assign.
…Variables
• You can change the value of a variable.
Simply assign it a new value in another assignment statement:
SMU Classification: Restricted
Variable Names
• There are a few rules for defining variable names:
• Names must start with a letter: 1a is not allowed
• You can have a mix of upper & lowercase letters, digits, or underscores
• case is important (a is not the same as A)
• Naming conventions in Python for variables (and functions):
• Use all lowercase letters with words separated by underscores to
improve readability. e.g. no_of_students
• Some programmers prefer noOfStudents (camel notation). This is also
fine, as long as you keep to the same notation consistently.
SMU Classification: Restricted
In-class Ex 3: T20-30
• The next Tutorial Project that you will attempt has got to do with computing the area of the
countertop:
Summary
What we have just covered:
• Arithmetic operations (operand, operator)
• Integers vs. floats
• Calling a function (e.g. sqrt)
– may need to import the relevant module which
contains the function (e.g. sqrt is in the math module)
• Using variables
SMU Classification: Restricted
1. Attempt Lab 0:
– https://colab.research.google.com/dr
ive/1ngyjYByDKC7rzMHsPOPZrMIXpu
2DFu0Q