🧠 Python If-Else Statement – Notes in Simple Hinglish
➤ if statement
if condition:
# agar condition true ho to yeh chalega
Example:
age = 18
if age >= 18:
print("You are eligible to vote.")
➤ if-else statement
if condition:
# true
else:
# false
Example:
marks = 35
if marks >= 33:
print("Pass")
else:
print("Fail")
➤ if-elif-else
if condition1:
# true
elif condition2:
# true
else:
# all false
Example:
num = 0
if num > 0:
print("Positive")
elif num < 0:
print("Negative")
else:
print("Zero")
🔁 Python For Loop – Notes in Simple Hinglish
for variable in range(start, end):
# loop chalega
➤ Basic Example:
for i in range(5):
print(i)
Output:
0
1
2
3
4
➤ Using range(start, end, step):
for i in range(1, 11, 2):
print(i)
Output:
1
3
5
7
9
✅ Practice Exercises with Solutions
Q1. Ek number input lo. Agar vo even ho to "Even" print karo, warna "Odd" print karo.
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")
Q2. 1 se 10 tak ke numbers print karo using for loop.
for i in range(1, 11):
print(i)
Q3. Ek number input lo. Agar vo 0 se chhota hai to "Negative", 0 hai to "Zero", aur agar 0 se bada hai to "Positive" print karo.
num = int(input("Enter number: "))
if num < 0:
print("Negative")
elif num == 0:
print("Zero")
else:
print("Positive")
Q4. Ek number input lo. Uska table print karo (jaise 5 ka table).
num = int(input("Enter number: "))
for i in range(1, 11):
print(num, "x", i, "=", num*i)
Q5. 1 se 100 ke beech ke sabhi even numbers print karo.
for i in range(1, 101):
if i % 2 == 0:
print(i)
Q6. Ek student ke marks input lo. Pass ho to "Pass", otherwise "Fail" print karo (passing marks = 33).
marks = int(input("Enter marks: "))
if marks >= 33:
print("Pass")
else:
print("Fail")
Q7. Ek list [1,2,3,4,5] ke sabhi numbers ko 2 se multiply karke print karo.
numbers = [1, 2, 3, 4, 5]
for num in numbers:
print(num * 2)
📘 Summary Table
Concept | Syntax | Use |
---|---|---|
if |
if condition: |
Jab ek condition true ho |
if-else |
if...else: |
Jab do possibilities ho (true/false) |
if-elif-else |
if...elif...else: |
Jab multiple conditions ho |
for loop |
for i in range(start, end): |
Jab repeat karna ho |
✅ Bonus: Want PDF for these notes?
Let me know, and I’ll generate a PDF with all notes + exercises formatted for print or class use.
Comments
Post a Comment