Lecture01 Note
Lecture01 Note
Lecture01 Note
CCE20003 PROGRAMMING I
Lecture 1
Spring 2015
Reading assignment:
Chapter 1 of the textbook
Learning programming with robots
(You may download the PDF file on Hisnet site)
GOALS OF THE COURSE CCE20003 HGU
Two-level goals
- Building up a basis on ICT (Information and
Communications Technology)
- Computational thinking and programming
(but not learning a programming language Python)
Knowledge
Declarative Imperative
Memory
Data Program
Instruction 1
Instruction 2
………………
Instruction k
………………
Instruction N
Processor
PC k
CCE20003 HGU
Computation
Top-down design
Multi-level abstraction
Divide and conquer
CCE20003 HGU
Low vs High
General vs Targeted
Compiled vs Interpreted
Open software
CCE20003 HGU
Why Python ?
A programming language easy to learn and very powerful
- Used in many universities for introductory courses
- Main language used for web programming at Google
- Widely used in scientific computation, e.g., at NASA
Characteristics of Python
Instruction set
Arithmetic and logical operations for defining
+, -, *, /, and ** expressions
and, or, not
Assignment
Conditionals
Iterations
Input/output
No pointers
No declarations
CCE20003 HGU
Why programming ?
Interactive mode
Python programs (scripts)
14
CCE20003 HGU
Interative mode
Script mode
Functions
A function definition specifies the name of a function
and the sequence of statements that are executed when
the function is called.
def print_message():
print "CCE20003 is fantastic!"
print "Programming is fun!"
Flow of execution
def print_message():
print "CCE20003 is fantastic!"
print "Programming is so much fun"
function definitions
def repeat_message():
print_message()
print message ()
repeat_message() function
print ‘Done’
calls
Execution begins at the first statement. Statements are executed
one by one, top to bottom.
Function definitions do not change the flow of execution
but only define a function.
Function calls are like detours in the flow of execution.
CCE20003 HGU
Comments
Turning right
Define a func-
tion!
def turn_right():
hubo.turn_left()
hubo.turn_left()
hubo.turn_left()
CCE20003 HGU
Newspaper delivery
Climbing up stairs
def climb_up_four_stairs():
climb_up_one_stair()
climb_up_one_stair()
climb_up_one_stair()
climb_up_one_stair()
def climb_up_one_stair():
hubo.turn_left()
hubo.move()
turn_right()
hubo.move()
hubo.move()
def turn_around():
hubo.turn_left()
hubo.turn_left()
CCE20003 HGU
Iteration: for-loops
def climb_up_four_stairs():
climb_up_one_stair()
climb_up_one_stair()
climb_up_one_stair()
climb_up_one_stair()
def climb_up_four_stairs():
for i in range(4):
climb_up_one_stair()
CCE20003 HGU