Learn Coding
57 subscribers
21 links
Download Telegram
⚠️ Made a discussion (Comments Section) for this Group!!
💡You can ask any questions there
Please open Telegram to view this post
VIEW IN TELEGRAM
📚 𝗟𝗲𝗰𝘁𝘂𝗿𝗲 𝟰 — 𝗖𝗼𝗻𝗱𝗶𝘁𝗶𝗼𝗻𝗮𝗹𝘀

So far your code runs top to bottom and does the same thing every time
No decisions, no logic — just straight execution
This lecture changes that

Conditionals let your code make decisions
Do this IF something is true — do that if it is not
This is the moment your code starts feeling like an actual program

This lecture covers:
➡️ if statements
➡️ else and elif
➡️ Comparison operators
➡️ Logical operators — and, or, not
➡️ Nested conditions
Please open Telegram to view this post
VIEW IN TELEGRAM
📌 The if Statement

An if statement runs a block of code only when a condition is true
If the condition is false — it skips that block entirely

age = 20

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


Two things to never forget:
➡️ The colon at the end of the if line
➡️ The indentation (4 spaces) before the code inside

Indentation is not optional in Python
It is literally how Python knows what belongs inside the if block
Miss it and your code breaks
Please open Telegram to view this post
VIEW IN TELEGRAM
📌 else and elif

else runs when the if condition is false:
age = 15

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


elif checks multiple conditions in order:
score = 75

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


Python checks from top to bottom
The moment one is true it runs that block and skips everything else
Please open Telegram to view this post
VIEW IN TELEGRAM
📌 Logical Operators — and, or, not

and — both conditions must be true:
age = 25
has_id = True

if age >= 18 and has_id:
print("Access granted")
else:
print("Access denied")


or — at least one must be true:
is_admin = False
is_owner = True

if is_admin or is_owner:
print("You can edit this")


not — flips the condition:
is_banned = False

if not is_banned:
print("Welcome back")


You will use these constantly in bots
Things like — if user is admin AND message is a command — do this
Please open Telegram to view this post
VIEW IN TELEGRAM
📌 Real Example — Simple Login Check

correct_password = "python123"

username = input("Enter username: ").strip().lower()
password = input("Enter password: ").strip()

if username == "admin" and password == correct_password:
print("Welcome back Admin!")
elif username == "admin" and password != correct_password:
print("Wrong password")
else:
print(f"User {username} not found")


Notice how we combined everything from the last 4 lectures
Variables, strings, input, f-strings, and now conditionals
This is how real programs are built — piece by piece
Please open Telegram to view this post
VIEW IN TELEGRAM
🚨 Video Reference

Watch this after reading through all the posts

Python Full Course 2024 — freeCodeCamp

🔖 Watch from 1:49:57 → 2:38:25
Covers conditionals, if/elif/else, modulo operator, and even/odd logic
Please open Telegram to view this post
VIEW IN TELEGRAM
✏️ Lecture 4 Homework

Build a number guessing hint program:

secret = 42
guess = int(input("Guess the number: "))

if guess == secret:
print("Correct!")
elif guess > secret:
print(f"Too high — you were off by {guess - secret}")
else:
print(f"Too low — you were off by {secret - guess}")


This is the base — now make it your own
Change the number, add more messages, make it interesting
Screenshot your output

Bonus — add a check: if the guess is within 5 of the secret, print "So close!"

⚠️ Next lecture drops in 2 days — Loops
Please open Telegram to view this post
VIEW IN TELEGRAM
This media is not supported in your browser
VIEW IN TELEGRAM
Got exams this week...
lectures might get delayed a little
📚 𝗟𝗲𝗰𝘁𝘂𝗿𝗲 𝟱 — 𝗟𝗼𝗼𝗽𝘀

So far your code runs once and stops
What if you need to do something 100 times?
You are not going to write 100 lines
That is where loops come in

A loop runs a block of code over and over until you tell it to stop

This lecture covers:
➡️ while loops — repeat while something is true
➡️ for loops — repeat for each item in a sequence
➡️ range() — generating number sequences
➡️ break and continue — controlling your loops
➡️ Nested loops
Please open Telegram to view this post
VIEW IN TELEGRAM
📌 While Loop

A while loop keeps running as long as a condition is true
The moment it becomes false — the loop stops

count = 1

while count <= 5:
print(f"Count: {count}")
count += 1

print("Done")


Output:


Count: 1
Count: 2
Count: 3
Count: 4
Count: 5
Done


count += 1 means count = count + 1
We increase count each time so the loop eventually stops

If you forget to update count the loop runs forever
This is called an infinite loop — press Ctrl+C to stop it
Please open Telegram to view this post
VIEW IN TELEGRAM
📌 For Loop

A for loop repeats for each item in a sequence
It is cleaner and safer than while for most situations

fruits = ["apple", "banana", "mango"]

for fruit in fruits:
print(fruit)


Output:
apple
banana
mango


You can also loop over a string — it goes letter by letter:

for letter in "Python":
print(letter)
Please open Telegram to view this post
VIEW IN TELEGRAM
📌 range()

range() generates a sequence of numbers for you to loop over

for i in range(5):
print(i)
# prints 0, 1, 2, 3, 4


```python
for i in range(1, 6):
print(i)
# prints 1, 2, 3, 4, 5


python
for i in range(0, 10, 2):
print(i)
# prints 0, 2, 4, 6, 8 (step of 2)`


range(start, stop, step)
Stop is always excluded — range(1, 6) gives you 1 to 5
Please open Telegram to view this post
VIEW IN TELEGRAM
📌 break and continue

break — exits the loop immediately:

for i in range(10):
if i == 5:
break
print(i)
# prints 0, 1, 2, 3, 4 then stops


continue — skips the current iteration and moves to the next:

for i in range(10):
if i % 2 == 0:
continue
print(i)
# prints only odd numbers: 1, 3, 5, 7, 9


You will use break a lot in bots
For example — keep asking for input until the user types something valid
Please open Telegram to view this post
VIEW IN TELEGRAM
📌 Real Example — Actual Number Guessing Game

Remember the homework from last lecture? Now we make it loop:

secret = 42
attempts = 0

while True:
guess = int(input("Guess the number: "))
attempts += 1

if guess == secret:
print(f"Correct! You got it in {attempts} attempts")
break
elif guess > secret:
print("Too high, try again")
else:
print("Too low, try again")


while True means loop forever
The only way out is the break when they guess correctly
This is a pattern you will see everywhere in real code
Please open Telegram to view this post
VIEW IN TELEGRAM
🚨 Video Reference

Watch this after reading through all the posts

Python Full Course 2024 — freeCodeCamp

🔖 Watch from 2:43:09 → 3:31:22
Covers while loops, for loops, lists, and escape sequences
Please open Telegram to view this post
VIEW IN TELEGRAM
✏️ Lecture 5 Homework

Build a multiplication table generator:

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

for i in range(1, 11):
print(f"{number} x {i} = {number * i}")


Run it with a few different numbers and screenshot the output

Bonus — wrap it in a while loop so after printing the table it asks
"Do you want another? (yes/no)" and keeps going until they say no

⚠️ Next lecture drops tomorrow — Lists & Tuples
Please open Telegram to view this post
VIEW IN TELEGRAM
This media is not supported in your browser
VIEW IN TELEGRAM
📚 𝗟𝗲𝗰𝘁𝘂𝗿𝗲 𝟲 — 𝗟𝗶𝘀𝘁𝘀 & 𝗧𝘂𝗽𝗹𝗲𝘀

Until now you stored one value in one variable
What if you need to store 100 values?
You are not making 100 variables
That is what lists are for

This lecture covers:
➡️ What lists are and how to create them
➡️ Accessing, updating, and deleting items
➡️ List methods
➡️ Looping through lists
➡️ Tuples — and when to use them instead
Please open Telegram to view this post
VIEW IN TELEGRAM