Unit 2
Unit 2
using Python
Unit 2
Prof. J. Katyayani
T. Jahnavi
The output of the function can be Output can not pass to other
pass to other function. function.
2. i = 10
if i > 25:
print("condition is satisfied")
2. i = 50
if i > 25:
print("condition is satisfied")
else:
print("condition is not satisfied")
Prof J. Katyayani, T.Jahnavi
Example
# python program to illustrate if else statement
i = 20
if (i < 15):
print("i is smaller than 15")
print("i'm in if Block")
else:
print("i is greater than 15")
print("i'm in else Block")
2. for j in range(0,10):
print(j, end = " ")
3. numbers = [6,5,3,8,4,2,5,4]
sum = 0
for val in numbers:
sum =sum + val
print("the sum is:", sum)
Prof J. Katyayani, T.Jahnavi
while loop
• In Python, while loops are used to execute a
block of statements repeatedly until a given
condition is satisfied.
• Then, the expression is checked again and, if it
is still true, the body is executed again.
• This continues until the expression becomes
false.
print(“Loop ends”)