DAY 3 OF PYTHON NOTES

 DAY 3 OF PYTHON NOTES 

๐Ÿ”น 1. Conditional Statements (if, elif, else)

✅ Basic Structure:

python
if condition: # code block elif another_condition: # another block else: # fallback block

๐Ÿ“Œ Example:

python
age = 18 if age >= 18: print("You are an adult.") elif age >= 13: print("You are a teenager.") else: print("You are a child.")

๐Ÿ”น 2. Comparison Operators

OperatorMeaning
==Equal to
!=Not equal to
>Greater than
<Less than
>=Greater than or equal
<=Less than or equal

๐Ÿ”น 3. Logical Operators

OperatorMeaningExample
andTrue if both conditionsa > 5 and a < 10
orTrue if one is truea < 5 or a > 15
notNegates the conditionnot(a == b)

๐Ÿ”น 4. Practice Problems

  1. Check if a number is even or odd.

python
num = int(input("Enter a number: ")) if num % 2 == 0: print("Even") else: print("Odd")
  1. Check if a number is positive, negative, or zero.

python
num = int(input("Enter a number: ")) if num > 0: print("Positive") elif num < 0: print("Negative") else: print("Zero")
  1. Find greater of two numbers.

python
a = int(input("Enter a: ")) b = int(input("Enter b: ")) if a > b: print("A is greater") else: print("B is greater or equal")

๐Ÿ”น 5. Intro to Loops: while Loop

✅ Syntax:

python
while condition: # code block

๐Ÿ“˜ Example:

python
i = 1 while i <= 5: print(i) i += 1
BY-ABHITECH

Comments

Popular posts from this blog

DAY 4 OF PYTHON NOTES

DAY ONE OF PYTHON NOTES BY ABHI TECH