There are two types of flow control.
1. Decision Control (if, if-else, if elif else)
2. Iterative control (while,for)
do while and switch are not available in Python.
Transfer Statements: Three transfer statements are available in Python namely break, continue and pass.
So without wasting much more time on theory we will learn all of these using simple scripts.
Decision Control:
if block is executed when condition given in that is True.
Here indentation is most important.
Indentation defines the scope of the block.
Problem1: Write a script which check whether the number entered by user is even or odd.
n=int(input("Enter the number: "))
if n%2==0:
print("Even")
else:
print("Odd")
1. Decision Control (if, if-else, if elif else)
2. Iterative control (while,for)
do while and switch are not available in Python.
Transfer Statements: Three transfer statements are available in Python namely break, continue and pass.
So without wasting much more time on theory we will learn all of these using simple scripts.
Decision Control:
if block is executed when condition given in that is True.
Here indentation is most important.
Indentation defines the scope of the block.
Problem1: Write a script which check whether the number entered by user is even or odd.
n=int(input("Enter the number: "))
if n%2==0:
print("Even")
else:
print("Odd")
Problem2: Write a program which takes a number from user, if it is greater than 0 print positive, if less than 0 print negative if 0 print neutral.
n=int(input("Enter the number: "))
if n>0:
print("Positive")
elif n<0:
print("Negative")
else:
print("Neutral")
Be First to Post Comment !
Post a Comment