Professional Documents
Culture Documents
CENG240-2021 Week5 Conditional and Repetitive Execution
CENG240-2021 Week5 Conditional and Repetitive Execution
CENG240-2021 Week5 Conditional and Repetitive Execution
Disclaimer: Figures without reference are from either from “Introduction to programming concepts
with case studies in Python” or “Programming with Python for Engineers”, which are both co-authored
by me.
Variables, Values and Aliasing in
0!
24
NG
on
CE
Python
METU Computer Engineering
ly
Every data
us
¢
vio
This is called
Aliasing.
2021 S. Kalkan - CEng 240 2
METU Computer Engineering
2021
Pre
vio
us
ly
on
CE
NG
24
0!
2021
Pre
vio
us
ly
on
CE
NG
24
0!
4
0!
Actions for I/O
24
NG
CE
on
METU Computer Engineering
ly
>>> print("I am %f tall, %d years old and have %s eyes" % (1.7569, 20, "blue"))
us
>>> print("I am %.2f tall, %d years old and have %s eyes" % (1.7569, 20, "blue"))
I am 1.76 tall, 20 years old and have blue eyes
¢ %f à Data identifier
¢ We have the following identifiers in Python:
0!
24
NG
on
CE Comments
METU Computer Engineering
ly
us
vio
Pre
0!
24
NG
on
CE pass statement
METU Computer Engineering
ly
us
vio
Pre
2021
Pre
vio
us
ly
on
CE
NG
24
0!
8
METU Computer Engineering
2021
Pre
vio
us
ly
on
CE
NG
24
0!
9
Writing your actions:
0!
24
NG
(1) Interact with the interpreter
on
CE
METU Computer Engineering
ly
us
vio
Pre
0!
24
NG
(2) Putting your actions into a script file
on
CE
METU Computer Engineering
ly
us
vio
Pre
0!
24
NG
(2) Putting your actions into a script file
on
CE
METU Computer Engineering
ly
us
vio
Pre
0!
24
NG
on
CE
(3) Your actions in a module
METU Computer Engineering
ly
us
vio
Pre
To reload:
>>> from importlib import reload
>>> reload(test)
¢ Conditional Execution
§ if statement
§ Conditional expression
¢ Repetitive Execution
§ while/for statement
§ break/continue statements
§ Set/list comprehension
CONDITIONAL EXECUTION
REPETITIVE EXECUTION
¢ <var> will
point to
the next
item in the
list.