Showing posts with label coding lessons. Show all posts
Showing posts with label coding lessons. Show all posts

Monday, March 16, 2026

Lesson 6: Lists, Tuples, and Dictionaries | Coding Class Series

March 16, 2026 0



Lesson 6: Lists, Tuples, and Dictionaries | Coding Class Series

Introduction

Welcome to Lesson 6!
In this lesson, we will learn about Python data structures: lists, tuples, and dictionaries. These structures help you store and organize multiple values efficiently.


1. Lists

A list is an ordered and mutable collection of items.
You can add, remove, or change elements in a list.

Syntax:

fruits = ["apple", "banana", "cherry"]
print(fruits[0])  # Access first item

Common List Methods:

fruits.append("orange")     # Add item
fruits.remove("banana")     # Remove item
fruits.sort()               # Sort items
print(fruits)

2. Tuples

A tuple is ordered but immutable.
Once created, you cannot change its elements.

Syntax:

coordinates = (10, 20)
print(coordinates[0])

Why use tuples?

  • They are faster than lists
  • Useful for data that should not change, like coordinates or constants.

3. Dictionaries

A dictionary stores key-value pairs.
You can access values using keys, not indexes.

Syntax:

student = {"name": "Alice", "age": 16, "grade": "A"}
print(student["name"])  # Output: Alice

Common Dictionary Methods:

student["age"] = 17        # Update value
student["city"] = "Delhi"  # Add new key-value pair
print(student.keys())      # Show all keys
print(student.values())    # Show all values

Practice Exercises

  1. Create a list of your 5 favorite movies. Print them in alphabetical order.
  2. Create a tuple of your 3 favorite colors and try to change one color (observe what happens).
  3. Create a dictionary for a book: title, author, year. Update the year and print all keys and values.
  4. Use a list of dictionaries to store 3 students’ information and print each student’s name and grade.


Lesson 5: Conditional Statements and Loops | Coding Class Series

March 16, 2026 0



Lesson 5: Conditional Statements and Loops | Coding Class Series

Introduction

Welcome to Lesson 5!
In this lesson, we will learn how to make decisions in your code using conditional statements (if, elif, else) and how to repeat tasks efficiently using loops (for and while).


Conditional Statements

Conditional statements let your program execute code based on certain conditions.

Syntax in Python:

age = 18

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

Explanation:

  • if age >= 18: → checks if the condition is True
  • else: → executes if the condition is False

Example with multiple conditions:

marks = 75

if marks >= 90:
    print("Grade: A")
elif marks >= 75:
    print("Grade: B")
else:
    print("Grade: C")

Loops

Loops allow repeating code multiple times without rewriting it.

For Loop

Used to iterate over sequences like lists, strings, or ranges.

for i in range(1, 6):
    print(f"Number: {i}")

Output:

Number: 1
Number: 2
Number: 3
Number: 4
Number: 5

While Loop

Executes code as long as a condition is True.

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

Output:

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

Practice Exercises

  1. Write a program to check if a number is positive, negative, or zero using if-elif-else.
  2. Print all even numbers from 1 to 50 using a for loop.
  3. Use a while loop to print the first 10 Fibonacci numbers.
  4. Write a program to count the number of vowels in a string using a loop.


क्या मैं Lesson 6 भी बना दूँ?