03 Python - Decision Making and Looping
03 Python - Decision Making and Looping
Tushar B. Kute,
http://tusharkute.com
Decision Making Statement
if-elif-else
if condition: if condition:
1 statements statement-1
elif condition:
Statement-2
if condition: else: 3
2 Statement-1 Statement-3
else:
Statement-2
if-else
Indentation
if-elif-else
Condition in if-else
• Example:
– Read three numbers from keyboard and
find largest of them. You are not allowed to
use ‘and’ and ‘or’ operators.
Example:
Example:
2
The else statement
...
1 6 7 8 4
>>> for n in 1,6,7,8,4:
... print(n*n, end=' ') Operation on data
...
1 36 49 64 16
>>> for n in 'h',23,3.12,12:
... print(n, end=' ') Mixed Elements
...
h 23 3.12 12
More on ‘for’ loop
The range( ) function
0 1 2 3 4 5 6 7 8 9
>>> for x in range(1,10,2):
print(x, end=' ')
1 3 5 7 9
The range( ) decrement operation
X = [4,7,9,1,5] # list
>>> for num in x:
print(num, end=' ')
4 7 9 1 5
>>> s = 'MITU Skillologies' # string
>>> for data in s:
print(data, end=' ')
M I T U S k i l l o l o g i e s
Collection of strings
0 1 2 3 4 5 6 7 8 9 Loop Ended
Example:
Web Resources
http://mitu.co.in
http://tusharkute.com
contact@mitu.co.in
tushar@tusharkute.com