Comprehensive notes Python Conditional statements class 11

The Comprehensive notes Python Conditional statements class 11 provides you notes for the topics if, if-else, if-elif-else python statements. So here we start!

Now you are familiar with how to use Operators, write expressions, accepting input and output statements in python.

Python Conditional statements class 11

So today you will read about conditional statements in python. When you are doing a specific task many situations occurred where you have to take the decision out of a few choices. For example: After passing class 10 which stream to choose Science, Commerce or Humanity, In science elective subjects which subject to opt etc.

So in programming also same conditions arise. In this case, conditional statements help to solve a problem. So let we start with conditional statements.

So this article Python Conditional statements class 11 will focus on following conditional statements:

Conditional Statements in python

Python allows the following conditional statements:

  1. Simple if: A program has only choice or condition is known as simple if.
  2. If…else: A program has two choices or condition is known as if..else. For Ex. The number is odd or even.
  3. If…elif…else: A program has more than two choices. For Ex. The number is positive, negative or zero. 
  4. Nested if: An if condition contains another if condition inside a block is known as nested if.

Relational operators and logical operators are used with conditional statements.

So lets understand the first topic of Python Conditional statements class 11.

Simple if

Lets have a look on syntax of simple if in Python Conditional statements class 11.

Syntax: 

if <condition>:
  statement

Example: 

A program to check the username is admin or not. (The username is case sensitive)

username=input("Enter username:")
if username=='admin':
    print("You are logged in successfully!!!")

A program to check eligibility for the senior citizen concession. (Age>65 years)

age=int(input("Enter the age:"))
if age>65:
    print("Concession Allowed")

The next topic of Python Conditional statements class 11 is if-else statement.

If-else

Syntax:

if <condition>:
     statements
else:
    statements

Example:

A program to check username and password is correct or not. (User:Admin, Password:123)

username=input("Enter username:")
password=input("Enter password:")
if username=='admin' and password=='123':
    print("Welcome", username)
else:
    print("Username or password is incorrect:")

A program to check a student is pass or fail. (Student must secure 33 marks in each subject)

eng=float(input("Enter marks of English:"))
hin=float(input("Enter marks of Hindi:"))
maths=float(input("Enter marks of Maths:"))
sci=float(input("Enter marks of Science:"))
soc=float(input("Enter marks of Social Sceince:"))
if eng<33 or hin<33 or maths<33 or sci<33 or soc<33:
    print("Fail")
else:
    print("Pass")

Watch this video lesson for more details:

After if-else lets explore if-elif-else statement for Python Conditional statements class 11.

if..elif..else

Syntax:

if <condition>:
   statements
elif <condition>:
   statements
else:
  statements

Example:

A program to check whether the number is one digit, two-digit or three-digit number. 

no=int(input("Enter number:"))
if no> 0 and no<10:
    print(no," is one digit no.")
elif no>0 and no<100:
    print(no," is two digit no.")
elif no>0 and no<1000:
    print(no," is three digit no.")
else:
    print("Number is more than three digit or negative")

A transport company compute fares as follows :

Distance in KilometersFare
0-100Rs. 15 per km
101-300Rs. 1500 plus Rs. 14.00 per km excess of 100
301-500Rs. 4300 plus Rs. 12.00 per km excess of 300
500 and aboveRs. 6700 plus Rs. 11.00 per km excess of 500
dist=int(input("Enter distance in km:"))
if dist> 0 and dist<=100:
    fare=dist*15
elif dist>100 and dist<=300:
    fare=1500+((dist-100)*14)
elif dist>300 and dist<=500:
    fare= 4300 + ((dist-300)*12)
elif dist>500:
    fare= 6700 + ((dist-500)*11)
print(fare)

Watch this video to understand the topic:

Nested…if

Example:

A cloth showroom has announced the following seasonal discounts on the purchase of items :

Purchase AmountDiscount Mill Cloth                      Handloom items
         0-1000   –                                      5%
         1001-2000   5%                               7.5%
         2001-3000   7.5%                            10.0%
         Above 3000   10.0%                          15.0%

Write a program to compute the net amount to be paid by a customer.

amt=float(input("Enter the bill amount:"))
cloth_type=input("Enter cloth type(M/H):")
if amt> 0 and amt<=1000:
    if cloth_type=='M':
        dis=0
    if cloth_type=='H':
        dis = amt*0.05
elif amt>1000 and amt<=2000:
    if cloth_type=='M':
        dis=amt*0.05
    if cloth_type=='H':
        dis = amt*0.075
elif amt>2000 and amt<=3000:
    if cloth_type=='M':
        dis=amt*0.075
    if cloth_type=='H':
        dis = amt*0.1
elif amt>3000:
    if cloth_type=='M':
        dis=amt*0.1
    if cloth_type=='H':
        dis = amt*0.15
amt=amt-dis
print("Discount amount is:",amt)
print("Net Amount is:",amt)

So I hope enjoyed this article and learnt the conditional statements. Find the following list of programs for your practice.

Practice Programs

Comment Your Views

%d bloggers like this: