Dragona_Pro

🔰 Introduction :

The current image has no alternative text. The file name is: IMG_20250722_015811_edit_55078523238469-1-scaled.jpg

In programming, we often need to repeat the same code multiple times. For example:

Printing numbers from 1 to 10.

Checking elements in a list.

Repealing a game until the player loses.

Instead of manually repeating the code, we use for and while loops.

🌀 First: The for loop

✅ General form :

Python

for a variable in an array:

# Iterate code

📦 The most famous example – using range():

Python

for i in range(5):

print(i)

📌 Result :

0

1

2

3

4

🔎 range(5) means: from 0 to 4 (5 not included).

🔁 Printing numbers from 1 to 10 :

Python

for i in range(1, 11):

print(i)

🪄 Simple exercise :

Write code that prints the sentence “Hello!” Five times:

Python

for i in range(5):

print(“Hello!”)

🧮 Practical example: Multiplication table

Python

number = int(input(“Pick a number: “))

for i in range(1, 11):

print(number, “x”, i, “=”, number * i)

🔄 Second: The while loop

✅ General form :

Python

while condition:

# code that repeats

📌 The while is used when you don’t know the number of iterations in advance.

⏳ Simple example :

Python

i = 1

while i <= 5:

print(“Repeat number”, i)

i += 1

⚠️ Important warning :

Beware of infinite loops! If you forget to update the condition inside the while statement, it will run forever:

python

# This code will not stop!

while True:

print(“Always on”)

🧪 Exercise 1 :

Ask the user for a password, and repeat the request until they type it correctly:

python

password = “”

while password != “python123”:

password = input(“Enter password: “)

print(“Login successful!”)

🔁 Exercise 2 :

Write code that asks the user for a number, then prints from 1 up to that number:

python

n = int(input(“Enter a number: “))

for i in range(1, n + 1):

print(i)

🔄 The difference between for and while

The for loop property while loop

The number of iterations is known Yes No Always

Usage: Lists, range(), defined iterations, conditional conditions, loops of unknown duration

📝 Summary :

You have learned to use for and while to repeat commands.

You have understood the difference between loops.

I used range() and tried practical examples.

📌 What will we learn in Lesson 5 ?

In the next lesson, we’ll learn how to organize code using functions. You’ll be able to reuse code in a smarter, more professional way.

كيفية تنزيل التطبيقات
انقر في الأسفل على تنزيل Dragon_Pro
ستظهر صفحة العد التنازلي بعد الانهاء من العد انقر على تحميل الان
ثم في الاسفل انقر على تحميل عادي
انتضر حتى ينتهي العد مرة اخرى
ستظهر ايقونة ابدا تحميل الان
انقر عليها سيتم تحميل التطبيق

How to download apps Click Download Dragon_Pro

at the bottom.
A countdown page will appear. After the countdown is complete, click Download Now. Then at the bottom, click Normal Download.
Wait for the countdown to finish again Then the Start Download Now icon will appear.
Click it to download the app.

⬇️ Download Dragona_Pro تحميل

Related Posts

FlyFeditv

📘 Introduction In this project, you’ll create a command-line Expense Tracker that allows users to: ✅ Add expenses with category, amount, and description✅ View total spending and category breakdown✅ Automatically…

Read more

NetCinFly

📘 Introduction In this project, you’ll develop a Student Grades Analyzer in Python that can: This project helps you strengthen your skills with lists, dictionaries, loops, and data analysis logic….

Read more

Eagle_Pro

🌐 Introduction In this project, you’ll create a Web Scraper App in Python that extracts quotes, authors, and tags from a live website.You’ll use the BeautifulSoup and Requests libraries to…

Read more

Cobra_Pro

🌦️ Introduction In this project, you’ll build a Weather App in Python that retrieves live weather information from an online API.You’ll learn how to work with HTTP requests, JSON data,…

Read more

Show7-Pro

Concepts Covered: 🎯 Objective: Create a simple, text-based contact book application that allows users to: 💡 Code (contact_book.py): 🧠 Example Usage Console Output Example: 💾 Notes ⬇️ Download Show7-Pro تحميل…

Read more

Rapid_tv

🔹 Introduction The Rock, Paper, Scissors Game is a classic hand game that you can easily build in Python. 👉 Rules: 🔹 Code Example 🔹 Example Run 🔹 Concepts Learned…

Read more