Session #4-5
Session #4-5
Overview
● Conditional statements
● If then else
Conditional statements
Syntax:
if condition:
Statement
TASK: Get 2 user inputs and check if the first one is bigger than the second
one
Else
An else statement performs the actions or computations if condition for
the if statement is not satisfied. There are no conditions for else.
Syntax:
else:
Statement
Syntax:
elif condition:
Statement
TASK: Get 2 user inputs, if they are not equal print the larger one otherwise
print that they are equal.
Challenges
1. Get input from the user and:
a. Check weather a number is positive, negative or zero.
b. All the years that are perfectly divisible by 4 are called as Leap years except the
century years. If the century year is divisible by 400 then that year is a Leap year.
Century year’s means they end with 00 such as 1200, 1300, 2400, 2500 etc. They
are divisible by 100. Check weather a year is a leap year or not.
c. A triangle is valid if sum of its two sides is greater than the third side. If three sides
are a, b and c, then three conditions should be met. Check weather three angles
of a triangle form a valid triangle
2. Ask the user input for 2 numbers and print the highest number
Challenges
3. A school has following rules for grading system:
0 to 25 -> F
26 to 45 -> E
46 to 50 -> D
51 to 60 -> C
61 to 80 -> B
81 to 100 -> A
5. A shop will give discount of 10% if the total purchase is above Rs. 1000/-. Let
us assume that an item cost is Rs. 100/-. Ask the user to input the number of
items bought, print the total amount payable by the customer.