DAY 4 OF PYTHON NOTES

DAY 4 OF PYTHON NOTES

๐Ÿ”น 1. for Loop Basics

✅ Syntax:

python
for variable in range(start, stop, step): # code block
  • start: where to begin (default is 0)

  • stop: where to end (not included!)

  • step: how much to increment (default is 1)


๐Ÿ”น 2. Using range()

๐Ÿ“˜ Examples:

python
# Print 1 to 5 for i in range(1, 6): print(i) # Print 0 to 9 for i in range(10): print(i) # Print even numbers from 2 to 10 for i in range(2, 11, 2): print(i) # Print in reverse (10 to 1) for i in range(10, 0, -1): print(i)

๐Ÿ”น 3. Pattern Printing with Loops

✅ Print 5 stars:

python
for i in range(5): print("*")

✅ Print stars in one line:

python
for i in range(5): print("*", end=" ")

✅ Print triangle pattern:

markdown
* * * * * * * * * *
python
for i in range(1, 5): print("* " * i)

๐Ÿ”น 4. Nested for Loops

Used to print grids, tables, patterns, etc.

๐Ÿ“˜ Print a 3x3 grid of stars:

python
for i in range(3): for j in range(3): print("*", end=" ") print()

๐Ÿ”น 5. Practice Problems

  1. Print first 10 even numbers using for loop.

  2. Print the multiplication table of a given number.

  3. Print a square pattern of # of size 4x4.

  4. Print numbers divisible by 3 between 1 and 50.

  5. Print reverse pattern:

markdown
* * * * * * * * * *

๐Ÿ”š Summary

ConceptUse Case
for + rangeRepeating with known count
end=' 'Print on the same line
Nested loopsPatterns, grids, tables

                                                                                                                                       BY-ABHITECH

Comments


  1. Wow your blog sach me bahut hi lajawab hai mene adhi Jayada information apne collages ke project submit ki hai jisme ye batya gye hai compute course kitna jada benefir course hai computer ki jarurat har sector me padti hai or apko blog me article computer ke bare me maja a gye sach thanks you ese article submit karne ke liye
    Graphic Designing course in Delhi NCR,
    Best computer course in Delhi
    Best Fine art Institute in Delhi

    ReplyDelete

Post a Comment

Popular posts from this blog

DAY 3 OF PYTHON NOTES

DAY ONE OF PYTHON NOTES BY ABHI TECH