0% found this document useful (0 votes)
3 views2 pages

Python Conditional Statements Notes

The document explains control statements in Python, which manage the execution flow of programs, including sequential, conditional, and iterative types. It details conditional statements, including 'if', 'if...else', and 'if...elif...else', and emphasizes the importance of indentation for code blocks. Additionally, it provides example programs demonstrating the use of conditional statements for various scenarios such as checking even/odd numbers, leap years, and discount calculations.

Uploaded by

haifaa00
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Python Conditional Statements Notes

The document explains control statements in Python, which manage the execution flow of programs, including sequential, conditional, and iterative types. It details conditional statements, including 'if', 'if...else', and 'if...elif...else', and emphasizes the importance of indentation for code blocks. Additionally, it provides example programs demonstrating the use of conditional statements for various scenarios such as checking even/odd numbers, leap years, and discount calculations.

Uploaded by

haifaa00
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Unit – 3: Conditional Statements in Python

1. What are control statements? How many types of control


statements are there in Python?
Control statements in Python manage the sequence of execution in a program. They help make decisions,
repeat actions, and control the overall flow of code.

• Sequential statements

• Conditional statements

• Iterative statements (loops)

2. What do you mean by conditional statements? How many types are


there?
Conditional statements allow a computer to check a condition and perform actions based on whether the
condition is true or false.

• if statement

• if…else statement

• if…elif…else statement

3. Purpose of indentation in Python


Indentation shows which statements belong to a block of code. In Python, correct indentation is required or
the program will produce an error.

4. Difference between if and if…else


if: Executes a block only when the condition is true.
if…else: Executes one block if the condition is true, otherwise another block.

5. How if–elif–else works


• if checks the first condition

• elif checks additional conditions

• else runs if none of the conditions are true

Apply Your Learning

1. Program to check if a number is even or odd


num = int(input("Enter a number:"))

if num % 2 == 0:
print("The number is even")
else:
print("The number is odd")
2. Program to print absolute value of a number
n = int(input("Enter a number:"))

if n < 0:
print(-n)
else:
print(n)

3. Program to check leap year


year = int(input("Enter a year:"))

if year % 4 == 0:
print("Leap year")
else:
print("Not a leap year")

4. Program to check if triangle is possible


a = int(input("Enter first angle:"))
b = int(input("Enter second angle:"))
c = int(input("Enter third angle:"))

if a + b + c == 180:
print("Triangle is possible")
else:
print("Triangle is not possible")

5. Discount program based on age and membership


age = int(input("Enter age:"))
member = input("Are you a member? (yes/no):")

if age >= 60 and member == "yes":


print("Discount: 20%")
elif age >= 60 and member == "no":
print("Discount: 10%")
elif age < 60 and member == "yes":
print("Discount: 5%")
else:
print("No Discount")

You might also like