Conditional - While - Loop - Jupyter Notebook
Conditional - While - Loop - Jupyter Notebook
hii
out of if
if condition:
# block of statements
else:
# block of statements
else:
# block of statements
enter a number: -5
Odd and -ve
elif expression 2:
# block of statements
elif expression 3:
# block of statements
else:
# block of statements
While Loop
Python while loop is used to run a block code until a certain conditio
n is met.
initialization
while condition:
#body of while
increment/decrement
In [19]: i = 1
while i<=6:
print(i)
i+=1
1
2
3
4
5
6
If the condition of a loop is always True, the loop runs for infinite
times (until the memory is full). For example,
In [1]: age = 32
# the test condition is always True
while age > 18:
print('You can vote')
break
The 👆 condition always evaluates to True. Hence, the loop body will
run for infinite times.
In [ ]: