Chapter-7 PYTHON CONTROL
Chapter-7 PYTHON CONTROL
CONTROL STRUCTURES IN
PYTHON
>>12+567 '45'
579 >>p+10
>>a,b=34,78 TypeError:
c=a+b >>s=int(input())
>>print(c) 23
112 >>s
>>p=input() 23
45 s+10
>>p 33
#WAP to accept 2 numbers and add them
a=int(input('Enter a number'))
b=int(input('Enter another number'))
sum=a+b
print('The sum is',sum)
#WAP to accept 2 numbers and find their
quotient
a=int(input('Enter a number'))
b=int(input('Enter another number'))
div=a/b
print('The quotient is',div)
#WAP to accept 3 numbers and find their
average
CONTROL
STRUCTURES
num1=int(input('Enter a number:'))
if num1>0:
print(num1,'is a positive number')
else:
print(num1,'is a negative number')
#WAP to accept a number and print whether
it an odd or an even number
num=int(input('Enter a number:'))
if num%2==0:
print(num,'is an even number')
else:
print(num,'is an odd number')
#WAP to accept marks and print grade
marks=int(input('Enter a number:'))
if marks>=90:
print('You have secured A grade')
elif marks>=80:
print('You have secured B grade')
elif marks>=70:
print('You have secured C grade')
elif marks>=60:
print('You have secured C grade')
else:
print('You have secured D grade')
ITERATIVE STATEMENTS
for s in range(4,34,5):
print(s)
Control Structure
A sequential structure is
also known as a straight
line path.
Sequential Statements
# Write a program to add two numbers.
Output:
Selection statements : These are also
known as branching statements or conditional
or decision-making statements. These
are used to select part of a program to be
executed based on the condition.
DO YOUR SELF
Example:
# Write a program to print table of 5
While loop
While Loop In Python is used to execute a block of statement till the given condition
is true. And when the condition is false, the control will come out of the loop.
Syntax
Output: Output:
apple apple
banana cherry
JUMP STATEMENTS
Output: Output:
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 9