Module 10:
LOOP AND ITERATION- PART 1
LOOP OR REPITITION STRUCTURE
– program need to be REPEATED
LOOP CONDITION
-repeating the instruction
LOOP EXIT CONDITION
-not repeating the instruction
Type of repetition
1. CONDITION CONTROLLED LOOP
-use true\false
- control number of time it repeated
2. COUNT CONTROLLED LOOP
-repeated specific number of time
INCREMENT and DECREMENT OPERATION
2 way of increment by 1
1. num = num + 1
2. num + = 1
2 way of decrement by 1
1. num = num – 1
2. num - = 1
WHILE LOOP
-repeated target as long as a given is true
Example:
ELSE STATEMENT WITH LOOP
-use when loop iterating the list
- execute when statement become false
Example:
Module 11:
LOOP AND ITERATION- PART 2
LOOP
-repeated until the condition is satisfied
Iteration_var
Example:
ITERATING BY SEQUENCE INDEX
-alternative way of iterating
-offset
Example:
ELSE STATEMENT WITH LOOP
Example:
FUNCTION RANGE
RANGE (n)
-starting from 0
Example:
Range(8) is equivalent to [0,1,2,3,4,5,6,7]
RANGE (start, stop)
starting to stop -1
Example:
Range (5,9) is equivalent to [5, 6, 7, 8]
RANGE ( start, stop, step_size)
Example:
NESTED LOOP
-use one loop inside another loop
Module 12:
LOOP CONTROLLED STATEMENT
When execute exit the loop all automatic object destroyed
Break statement
-to exit the loop
-to terminate the loop
Pass statement
-no operation
-valid but nothing happen actually
-indicate “null”
Module 13:
Logical operator in PYTHON
- making decision
-check multiple condition (TRUE or FALSE, YES or NO)
3 MAIN TYPE OF LOGICAL
1. NOT
-evaluate first
-not false evaluate as true
2. AND
-evaluate next
-false AND true evaluate as false
3. OR
-evaluate last
-true OR false evaluate as true
Level of precedence
1. NOT - high
2. AND - medium
3. OR - low
OR and AND precedence
-evaluate from left to right
QUIZ P2:
MODULE 15:
PYTHON BUILT IN FUNCTION – reusable piece of code
print () – output the message specified
-before written to the screen, the object will converted into a STRING
Print(object(s)
sep = separator – use if object more than 1 ‘’
end = end – what to print ‘/n’(line feed)
file = file - method
flush = flush -boolean
object(s) – as many as you like
example :
input – evaluating value
syntax – round (number, digits)
parameter – number should be rounded
0 – default
Example:
pow() – pow(a,b); compute raise power b
syntax – (x, y, z)
parameter – x(base), y(exponent), z(modulus)
example:
sum() – iterable
syntax – sum(iterable, start)
parameter – iterable – can be list, tuples, dictionaries
Example:
type() – class type of the argument
syntax – type (object, based, dict)
parameter – object required if one parameter is specified
dict – namespace
example: