? Python Review Session_ Basics to Nested Loops
? Python Review Session_ Basics to Nested Loops
Nested Loops
🔹 1. Introduction to Python
✅ Key Points:
● Python is interpreted, beginner-friendly, and uses indentation instead of braces.
🧪 Example:
# Hello world in Python
print("Hello, world!")
📝 HW:
● Print your name and your favorite programming language.
🧪 Example:
name = "Rahim"
age = 20
height = 5.6
is_student = True
print(name, age, height, is_student)
📝 HW:
● Create 3 variables: one int, one float, and one str, and print them all in a single line.
🧪 Example:
name = input("Enter your name: ")
print("Welcome,", name)
📝 HW:
● Ask the user for their city and favorite color. Print a greeting using both.
🔹 4. Type Conversion
✅ Key Points:
● Convert string inputs to numbers using int() or float()
🧪 Example:
num1 = int(input("Enter a number: "))
num2 = float(input("Enter another number: "))
print("Sum:", num1 + num2)
📝 HW:
● Take two inputs from the user as numbers and show their difference, product, and
division.
🔹 5. Arithmetic Operators
✅ Operators:
● +, -, *, /, //, %, **
🧪 Example:
a=9
b=2
print(a + b, a - b, a * b, a / b, a // b, a % b, a ** b)
📝 HW:
● Write a program that asks for 2 numbers and prints all arithmetic operations between
them.
🔹 6. Conditional Statements
✅ Key Points:
● Use if, elif, else for decision making.
🧪 Example:
age = int(input("Enter your age: "))
if age >= 18:
print("You are an adult.")
else:
print("You are a minor.")
📝 HW:
● Ask the user for a number. If it’s even, print "Even", otherwise print "Odd".
✅ Logical:
and, or, not
🧪 Example:
a = 10
b=5
print(a > b and b < 3) # False
📝 HW:
● Ask for a user’s age and nationality. If age ≥ 18 and nationality is "Bangladeshi", print
"Eligible".
🔹 8. While Loop
✅ Key Points:
● Repeats code while condition is True
🧪 Example:
i=1
while i <= 5:
print("Count:", i)
i += 1
📝 HW:
● Write a program to print numbers from 1 to 10 using while.
🔹 9. For Loop
✅ Key Points:
● Use range() for sequences
🧪 Example:
for i in range(5):
print("Hello", i)
📝 HW:
● Print all even numbers between 1 and 20 using a for loop.
🧪 Example:
for i in range(1, 4):
for j in range(1, 4):
print(f"({i},{j})", end=" ")
print()
📝 HW:
● Create a nested loop to print the following pattern:
***
***
***
If n = 4
*
**
***
****