Professional Documents
Culture Documents
PROGRAMMING
Session 4
Control Structures-If statement
Control Structures
◦ Control structures are used for non-sequential and repetitive
execution of instruction.
◦ If conditional Statements
◦ Iteration for and while statements
General form of a typical decision making structure in
most of the programming languages
◦ Syntax
if expression1:
statement(s)
elif expression2:
statement(s)
elif expression3:
statement(s)
else:
statement(s)
Example
if num > 0:
print("Positive number")
elif num == 0:
print("Zero")
else:
print("Negative number")
Program to try
◦ Q Ask user to enter his choice
◦ If choice entered is 1 then print the value of choice and also print
‘Hello and welcome to CS’
◦ Else if the user has entered 2 then print ‘the choice entered is
two’ and print ‘It’s a nice day’
◦ Else if the user has entered 3 print ‘Goodbye’
◦ Else if the user entered 4 print ‘ Enjoy python’
◦ In case any other value print wrong choice
Question
◦ Q Ask user to input his marks
◦ If marks entered are >=75 print ‘First division’
◦ If marks entered are <75 but more 60 print ‘Second division’
◦ If marks entered are <60 but more or equal to 40 print third
division
◦ Otherwise print Fail