Now, let’s move on to next topic in the Python coding challenge.
Operators in Python
Operators are special symbols or keywords that perform operations on variables and values.
Types of Operators in Python:
1. Arithmetic Operators
Used for basic math:
+ (add), - (subtract), * (multiply), / (divide), // (floor divide), % (modulus), ** (power)
a = 10
b = 3
print(a + b) # 13
print(a ** b) # 1000
2. Comparison Operators
Used to compare two values:
==, !=, >, <, >=, <=
x = 5
print(x == 5) # True
print(x != 3) # True
3. Logical Operators
Used to combine conditional statements:
and, or, not
age = 20
print(age > 18 and age < 25) # True
4. Assignment Operators
Used to assign values to variables:
=, +=, -=, *=, /=, etc.
score = 10
score += 5 # score is now 15
Mini Project: Build a Simple Calculator
Let’s apply what we’ve learned!
Task: Build a calculator that asks the user to enter two numbers and an operator, then prints the result.
Approach
1. Take two numbers from the user.
2. Ask for an operator (+, -, *, /).
3. Perform the operation based on what the user entered.
4. Print the result, or shows "Invalid operator!" if the input is wrong.
Python Code:
num1 = float(input("Enter first number: "))
op = input("Enter operator (+, -, *, /): ")
num2 = float(input("Enter second number: "))
if op == "+":
print(num1 + num2)
elif op == "-":
print(num1 - num2)
elif op == "*":
print(num1 * num2)
elif op == "/":
print(num1 / num2)
else:
print("Invalid operator!")
React with ❤️ once you’re ready for the quiz
Operators in Python
Operators are special symbols or keywords that perform operations on variables and values.
Types of Operators in Python:
1. Arithmetic Operators
Used for basic math:
+ (add), - (subtract), * (multiply), / (divide), // (floor divide), % (modulus), ** (power)
a = 10
b = 3
print(a + b) # 13
print(a ** b) # 1000
2. Comparison Operators
Used to compare two values:
==, !=, >, <, >=, <=
x = 5
print(x == 5) # True
print(x != 3) # True
3. Logical Operators
Used to combine conditional statements:
and, or, not
age = 20
print(age > 18 and age < 25) # True
4. Assignment Operators
Used to assign values to variables:
=, +=, -=, *=, /=, etc.
score = 10
score += 5 # score is now 15
Mini Project: Build a Simple Calculator
Let’s apply what we’ve learned!
Task: Build a calculator that asks the user to enter two numbers and an operator, then prints the result.
Approach
1. Take two numbers from the user.
2. Ask for an operator (+, -, *, /).
3. Perform the operation based on what the user entered.
4. Print the result, or shows "Invalid operator!" if the input is wrong.
Python Code:
num1 = float(input("Enter first number: "))
op = input("Enter operator (+, -, *, /): ")
num2 = float(input("Enter second number: "))
if op == "+":
print(num1 + num2)
elif op == "-":
print(num1 - num2)
elif op == "*":
print(num1 * num2)
elif op == "/":
print(num1 / num2)
else:
print("Invalid operator!")
React with ❤️ once you’re ready for the quiz
❤3
❤2
❤1
What does // do in Python?
Anonymous Quiz
15%
Division with remainder
13%
Regular division
63%
Floor division (no decimal part)
8%
Raise an error
❤1
❤1
Now, let's move to the next topic in the Python Coding Challenge:
Strings & String Methods
A string is a sequence of characters inside quotes. You can use:
name = "Alice"
greeting = 'Hello!'
paragraph = """This is
a multiline string."""
👉 Strings are immutable — once created, they can't be changed directly.
✨ Common String Methods
Here are some useful methods you’ll use all the time:
lower() → makes everything lowercase
upper() → makes everything uppercase
strip() → removes spaces from start and end
replace("old", "new") → replaces parts of a string
split() → splits text into a list of words
count("word") → counts how many times something appears
find("word") → finds the position of a word
startswith("Hello") → checks how a string begins
endswith("world") → checks how a string ends
🧪 Examples
msg = " Python is Awesome! "
print(msg.lower()) # python is awesome!
print(msg.strip()) # Python is Awesome!
print(msg.replace("Awesome", "Powerful")) # Python is Powerful!
print(msg.split()) # ['Python', 'is', 'Awesome!']
🛠 Project 1: Word Counter
text = input("Enter a sentence: ")
words = text.split()
print("Word count:", len(words))
Try it with:
> Python is easy and powerful
→ Output: 5
🌀 Project 2: Palindrome Checker
text = input("Enter a word: ")
if text == text[::-1]:
print("Palindrome!")
else:
print("Not a palindrome.")
Try:
- madam → Palindrome
- racecar → Palindrome
- hello → Not a palindrome
React with ❤️ once you’re ready for the quiz
Strings & String Methods
A string is a sequence of characters inside quotes. You can use:
name = "Alice"
greeting = 'Hello!'
paragraph = """This is
a multiline string."""
👉 Strings are immutable — once created, they can't be changed directly.
✨ Common String Methods
Here are some useful methods you’ll use all the time:
lower() → makes everything lowercase
upper() → makes everything uppercase
strip() → removes spaces from start and end
replace("old", "new") → replaces parts of a string
split() → splits text into a list of words
count("word") → counts how many times something appears
find("word") → finds the position of a word
startswith("Hello") → checks how a string begins
endswith("world") → checks how a string ends
🧪 Examples
msg = " Python is Awesome! "
print(msg.lower()) # python is awesome!
print(msg.strip()) # Python is Awesome!
print(msg.replace("Awesome", "Powerful")) # Python is Powerful!
print(msg.split()) # ['Python', 'is', 'Awesome!']
🛠 Project 1: Word Counter
text = input("Enter a sentence: ")
words = text.split()
print("Word count:", len(words))
Try it with:
> Python is easy and powerful
→ Output: 5
🌀 Project 2: Palindrome Checker
text = input("Enter a word: ")
if text == text[::-1]:
print("Palindrome!")
else:
print("Not a palindrome.")
Try:
- madam → Palindrome
- racecar → Palindrome
- hello → Not a palindrome
React with ❤️ once you’re ready for the quiz
❤2
what is the output of the following code ?
msg = " Learn Python " print(msg.strip())
msg = " Learn Python " print(msg.strip())
Anonymous Quiz
26%
" Learn Python "
35%
"Learn Python"
39%
"LearnPython"
0%
" Learn Python"
❤2
Q2. Which method is used to turn all characters in a string to uppercase?
Anonymous Quiz
8%
capital()
54%
upper()
15%
toupper()
23%
uppercase()
❤2
what is the result of this code?
text = " Python Programming " print(text.split())
text = " Python Programming " print(text.split())
Anonymous Quiz
54%
['Python', 'Programming']
32%
['P','y','t','h','o','n'']
7%
['PythonProgramming']
7%
['Python_Programming']
❤2
Q4. Which of these strings is a palindrome?
Anonymous Quiz
70%
"racecar"
22%
"Python"
9%
"banana"
0%
"hello"
❤2
❤3
Now, Let's move to the next topic in the Python Coding Challenge:
Lists & Tuples
🔹 What is a List?
A list is a mutable (changeable) collection of items in a specific order.
Syntax:
fruits = ["apple", "banana", "cherry"]
print(fruits[0]) # Output: apple
fruits.append("mango")
print(fruits) # Output: ['apple', 'banana', 'cherry', 'mango']
✅ You can add, remove, or update elements in a list.
🔸 What is a Tuple?
A tuple is similar to a list, but it's immutable (unchangeable once defined).
Syntax:
colors = ("red", "green", "blue")
print(colors[1]) # Output: green
🔒 You cannot modify, append, or remove elements from a tuple after creation.
✅ Key Differences:
Mutability:
- List: Mutable — you can change, add, or remove elements after creation.
- Tuple: Immutable — once defined, you cannot change, add, or remove elements.
Syntax:
- List: Use square brackets → []
my_list = [1, 2, 3]
- Tuple: Use round brackets → ()
my_tuple = (1, 2, 3)
Use Case:
- List: Use when you need to modify the collection later.
- Tuple: Use when the data should remain constant or to ensure integrity.
Performance:
Tuple is slightly faster than List due to immutability and fixed size.
🛠 Mini Project: Grocery List Manager
Let’s build a simple grocery list app where you can:
- Add items
- Remove items
- Display all items
Python Code:
grocery_list = []
while True:
print("\nOptions: add / remove / show / exit")
action = input("What would you like to do? ")
if action == "add":
item = input("Enter item to add: ")
grocery_list.append(item)
print(f"{item} added.")
elif action == "remove":
item = input("Enter item to remove: ")
if item in grocery_list:
grocery_list.remove(item)
print(f"{item} removed.")
else:
print("Item not found.")
elif action == "show":
print("Your grocery list:")
for i in grocery_list:
print("-", i)
elif action == "exit":
break
else:
print("Invalid option.")
✅ Try running this and see how lists work in real time!
React with ❤️ once you’re ready for the quiz
Lists & Tuples
🔹 What is a List?
A list is a mutable (changeable) collection of items in a specific order.
Syntax:
fruits = ["apple", "banana", "cherry"]
print(fruits[0]) # Output: apple
fruits.append("mango")
print(fruits) # Output: ['apple', 'banana', 'cherry', 'mango']
✅ You can add, remove, or update elements in a list.
🔸 What is a Tuple?
A tuple is similar to a list, but it's immutable (unchangeable once defined).
Syntax:
colors = ("red", "green", "blue")
print(colors[1]) # Output: green
🔒 You cannot modify, append, or remove elements from a tuple after creation.
✅ Key Differences:
Mutability:
- List: Mutable — you can change, add, or remove elements after creation.
- Tuple: Immutable — once defined, you cannot change, add, or remove elements.
Syntax:
- List: Use square brackets → []
my_list = [1, 2, 3]
- Tuple: Use round brackets → ()
my_tuple = (1, 2, 3)
Use Case:
- List: Use when you need to modify the collection later.
- Tuple: Use when the data should remain constant or to ensure integrity.
Performance:
Tuple is slightly faster than List due to immutability and fixed size.
🛠 Mini Project: Grocery List Manager
Let’s build a simple grocery list app where you can:
- Add items
- Remove items
- Display all items
Python Code:
grocery_list = []
while True:
print("\nOptions: add / remove / show / exit")
action = input("What would you like to do? ")
if action == "add":
item = input("Enter item to add: ")
grocery_list.append(item)
print(f"{item} added.")
elif action == "remove":
item = input("Enter item to remove: ")
if item in grocery_list:
grocery_list.remove(item)
print(f"{item} removed.")
else:
print("Item not found.")
elif action == "show":
print("Your grocery list:")
for i in grocery_list:
print("-", i)
elif action == "exit":
break
else:
print("Invalid option.")
✅ Try running this and see how lists work in real time!
React with ❤️ once you’re ready for the quiz
❤1
what is the output of the following code ?
fruits = ["apple","banana","cherry"]
print(fruits[1])
fruits = ["apple","banana","cherry"]
print(fruits[1])
Anonymous Quiz
29%
apple
67%
banana
0%
cherry
4%
None of the above
❤1
Q2. Which of these defines a tuple correctly?
Anonymous Quiz
30%
my_tuple = [1,2,3]
52%
my_tuple = (1,2,3)
17%
my_tuple = {1,2,3}
❤1
Which operation is not allowed on a tuple?
Anonymous Quiz
10%
Accessing an item
20%
iteration over the items
50%
Appending an item
20%
Checking length
❤1
What is the main difference between a list and a tuple?
Anonymous Quiz
26%
List is immutable, tuple is mutable
0%
Tuple allows duplicate values, list does not
74%
List is mutable, tuple is immutable
❤1
❤1
Today, let's move on to the next topic in the Python Coding Challenge:
Dictionaries & Sets 🔑🧺
🔹Day 5: What is a Dictionary in Python?
A dictionary is an unordered, mutable collection that stores data in key-value pairs.
🧠 Example:
student = {
"name": "Amit",
"age": 21,
"course": "Python"
}
print(student["name"]) # Output: Amit
- Keys must be unique and immutable (like strings, numbers).
- Values can be anything: strings, numbers, lists, or even other dictionaries.
🧰 Common Dictionary Methods:
student.get("age") # Returns 21
student.keys() # Returns all keys
student.values() # Returns all values
student.items() # Returns key-value pairs
student["grade"] = "A+" # Adds a new key-value pair
🔹 What is a Set in Python?
A set is an unordered collection of unique elements.
🧠 Example :
numbers = {1, 2, 3, 4, 4, 2}
print(numbers) # Output: {1, 2, 3, 4} — no duplicates
- Sets remove duplicates automatically.
- Useful for membership checks, uniqueness, and set operations (union, intersection).
✅ Real-Life Project: Contact Book using Dictionary
- Build a CLI-based contact book where users can:
- Add new contacts (name, phone)
- View all contacts
- Search by name
- Delete a contact
💡 Python Code:
contacts = {}
while True:
print("\n1. Add Contact\n2. View All\n3. Search\n4. Delete\n5. Exit")
choice = input("Enter choice: ")
if choice == '1':
name = input("Name: ")
phone = input("Phone: ")
contacts[name] = phone
print("Contact saved!")
elif choice == '2':
for name, phone in contacts.items():
print(f"{name} : {phone}")
elif choice == '3':
name = input("Enter name to search: ")
if name in contacts:
print(f"{name}'s phone: {contacts[name]}")
else:
print("Contact not found.")
elif choice == '4':
name = input("Enter name to delete: ")
if name in contacts:
del contacts[name]
print("Deleted successfully.")
else:
print("No such contact.")
elif choice == '5':
break
else:
print("Invalid choice.")
React with ❤️ once you’re ready for the quiz
Dictionaries & Sets 🔑🧺
🔹Day 5: What is a Dictionary in Python?
A dictionary is an unordered, mutable collection that stores data in key-value pairs.
🧠 Example:
student = {
"name": "Amit",
"age": 21,
"course": "Python"
}
print(student["name"]) # Output: Amit
- Keys must be unique and immutable (like strings, numbers).
- Values can be anything: strings, numbers, lists, or even other dictionaries.
🧰 Common Dictionary Methods:
student.get("age") # Returns 21
student.keys() # Returns all keys
student.values() # Returns all values
student.items() # Returns key-value pairs
student["grade"] = "A+" # Adds a new key-value pair
🔹 What is a Set in Python?
A set is an unordered collection of unique elements.
🧠 Example :
numbers = {1, 2, 3, 4, 4, 2}
print(numbers) # Output: {1, 2, 3, 4} — no duplicates
- Sets remove duplicates automatically.
- Useful for membership checks, uniqueness, and set operations (union, intersection).
✅ Real-Life Project: Contact Book using Dictionary
- Build a CLI-based contact book where users can:
- Add new contacts (name, phone)
- View all contacts
- Search by name
- Delete a contact
💡 Python Code:
contacts = {}
while True:
print("\n1. Add Contact\n2. View All\n3. Search\n4. Delete\n5. Exit")
choice = input("Enter choice: ")
if choice == '1':
name = input("Name: ")
phone = input("Phone: ")
contacts[name] = phone
print("Contact saved!")
elif choice == '2':
for name, phone in contacts.items():
print(f"{name} : {phone}")
elif choice == '3':
name = input("Enter name to search: ")
if name in contacts:
print(f"{name}'s phone: {contacts[name]}")
else:
print("Contact not found.")
elif choice == '4':
name = input("Enter name to delete: ")
if name in contacts:
del contacts[name]
print("Deleted successfully.")
else:
print("No such contact.")
elif choice == '5':
break
else:
print("Invalid choice.")
React with ❤️ once you’re ready for the quiz
❤2
What will be the output of following code?
d = {"a": 1, "b": 2} print(d.get("c"))
d = {"a": 1, "b": 2} print(d.get("c"))
Anonymous Quiz
7%
0
30%
Error
27%
None
37%
"c"
❤1
Which one of these is NOT allowed as a key in a dictionary?
Anonymous Quiz
21%
integer
14%
String
50%
Tuple
14%
List
❤2
Which method returns all key-value pairs in a dictionary?
Anonymous Quiz
32%
.Values()
18%
.get()
25%
.items()
25%
.keys()
❤1