0% found this document useful (0 votes)
6 views3 pages

Conditional_Statements_Classwork_and_Homework

The document covers various types of conditional statements in Python, including `if`, `if-else`, `elif`, and nested `if-else` statements. It provides examples for each type, demonstrating how to execute code based on conditions, and includes classwork exercises and homework tasks related to these concepts. The exercises focus on practical applications such as checking even or odd numbers, voting eligibility, and a login system.

Uploaded by

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

Conditional_Statements_Classwork_and_Homework

The document covers various types of conditional statements in Python, including `if`, `if-else`, `elif`, and nested `if-else` statements. It provides examples for each type, demonstrating how to execute code based on conditions, and includes classwork exercises and homework tasks related to these concepts. The exercises focus on practical applications such as checking even or odd numbers, voting eligibility, and a login system.

Uploaded by

Abdur Rahman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Class Topic: Conditional Statements

1. `if` Statement
Executes a block if the condition is True.

age = 18
if age >= 18:
print("You are an adult.")

2. `if-else` Statement
Choose between two blocks based on the condition.

age = 16
if age >= 18:
print("You are an adult.")
else:
print("You are a minor.")

3. `elif` (Else If)


For multiple conditions (Python-specific).

score = 75
if score >= 90:
print("Grade: A")
elif score >= 80:
print("Grade: B")
elif score >= 70:
print("Grade: C")
else:
print("Grade: F")

4. Nested `if-else`
An `if` or `else` block containing another `if-else`.

age = 20
has_id = True
if age >= 18:
if has_id:
print("You can enter.")
else:
print("ID required.")
else:
print("You are too young.")

Classwork (CW) Exercises


1. Check Even or Odd

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


if num % 2 == 0:
print("Even")
else:
print("Odd")

2. Check Voting Eligibility

age = int(input("Enter your age: "))


if age >= 18:
print("You can vote.")
else:
print("You cannot vote.")

3. Nested if-else: Pass/Fail with Grade

marks = int(input("Enter your marks: "))


if marks >= 40:
if marks >= 80:
print("Passed with distinction.")
else:
print("Passed.")
else:
print("Failed.")
Homework (HW) Tasks
1. Temperature Checker

Ask user for temperature:


- Above 30: Print "It's hot"
- 20–30: Print "Normal weather"
- Below 20: Print "It's cold"

2. Number Sign Checker

Take a number and print:


- "Positive" if > 0
- "Negative" if < 0
- "Zero" if == 0

3. Nested if-else for Login System

Ask for username and password:


- If username is "admin"
- Check if password is "1234": "Login successful"
- Else: "Incorrect password"
- Else: "Unknown user"

You might also like