Description for the above code
The above Python code will print the string "hello world" ten times. Here's a breakdown of how it works:
1. The for loop is set to iterate over the range from 1 to 10 inclusive. The range(1, 11) function generates a sequence of numbers starting from 1 up to (but not including) 11.
2. On each iteration of the loop, the print('hello world') statement is executed.
Because the loop iterates 10 times, "hello world" will be printed 10 times, each on a new line.
Here is the code:
Output
#ForLoop
@python_pioneers
@python_pioneers
The above Python code will print the string "hello world" ten times. Here's a breakdown of how it works:
1. The for loop is set to iterate over the range from 1 to 10 inclusive. The range(1, 11) function generates a sequence of numbers starting from 1 up to (but not including) 11.
2. On each iteration of the loop, the print('hello world') statement is executed.
Because the loop iterates 10 times, "hello world" will be printed 10 times, each on a new line.
Here is the code:
for i in range(1, 11):
print('hello world')
Output
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
#ForLoop
@python_pioneers
@python_pioneers
๐4๐ฅฐ2โค1
Everyone Has a Story in Life
A 24 year old boy seeing out from the trainโs window shoutedโฆ
โDad, look the trees are going behind!โ
Dad smiled and a young couple sitting nearby, looked at the 24 year oldโs childish behavior with pity, suddenly he again exclaimedโฆ
โDad, look the clouds are running with us!โ
The couple couldnโt resist and said to the old manโฆ
โWhy donโt you take your son to a good doctor?โ The old man smiled and saidโฆโI did and we are just coming from the hospital, my son was blind from birth, he just got his eyes today.โ
Every single person on the planet has a story. Donโt judge people before you truly know them. The truth might surprise you.
แแแซแ แแฝแต!
#EnglishStory
@python_pioneers
@python_pioneers
โค5๐1๐ฅฐ1
Forwarded from TIKVAH-MAGAZINE
#แฅแแ
แจแขแแแญแแฝแ แแจแฅ แฐแ แแแต แ แตแฐแณแฐแญ (แขแแณ) แ แแแญ แ แแ แฐแจแ แฅแตแแ แธแ แจ11 แ แแต แ แแญ แแแ แฅแ แแแแต แแแธแ แจแณแญแ แญ แญแ แแต แจแตแแ แ แแแแฃ แฅแ แจแปแแแ แแญแแแฅแญ แแแแฉแ แ แฐแ แ แแแฃแ แแแแซ แแแฟแแข
แฐแแ แ แแแ แจแแแชแฑ แญแแ แซแ แแฃแถแฝแ แแแแแฅ แจแแฝแ แแแแ แจแแแ แฒแแ แ แแแญ แ แแ แฐแจแ แจแแแแแก แฐแแฃแแฝแ แฐแจแ แ แฐแจแ แจแแแแแแ แต แแฐแ (แปแแแ ) แฅแ แญแ แแณแธแแ แจแแแญแ แต แณแญแแณแ แแตแแญแต แแแแแฑแ แฐแแแฟแแข
แฐแแ แจแแฐแฃแธแ แจแตแแ แ แแตแฎแฝ แแแตแแธแ แแธแ?
- แ แณแญแ แญ แฐแ แแแตแฃ
- แ แณแญแ แญ แฐแ แแแต แแญแ แจแตแจแแ แฃ แจแแฐแแ แชแซ แฅแ แฐแซแซแฅ แแแต (development)แฃ
- แจแตแแญแต แแฎแแญแต แฒแตแฐแแฝ แฃ
- แ แคแฎแตแแต แฅแ แแแฝแ แฅแแฐแแ แฐแแแฟแแข
แตแแ แแ แ แ แฒแต แ แ แฃ แฉแแจแญแฒแฒ แดแญแแแ แแ แแต แแญ แญแฐแฃแ แจแฐแฃแ แฒแแ แ แแแซแพแฝ แ แแฅแณแญแต https://talent.Insa.gov.et แ แแแฃแต แฅแตแจ แแแฆแต 30/ 2016 แ/แ แแแแแฅ แฅแแตแตแฝแ แฅแแ แแญแงแแข
แแ แแ แแจแ +251904311833 +251943579970
+251904311837
@TikvahethMagazine
แจแขแแแญแแฝแ แแจแฅ แฐแ แแแต แ แตแฐแณแฐแญ (แขแแณ) แ แแแญ แ แแ แฐแจแ แฅแตแแ แธแ แจ11 แ แแต แ แแญ แแแ แฅแ แแแแต แแแธแ แจแณแญแ แญ แญแ แแต แจแตแแ แ แแแแฃ แฅแ แจแปแแแ แแญแแแฅแญ แแแแฉแ แ แฐแ แ แแแฃแ แแแแซ แแแฟแแข
แฐแแ แ แแแ แจแแแชแฑ แญแแ แซแ แแฃแถแฝแ แแแแแฅ แจแแฝแ แแแแ แจแแแ แฒแแ แ แแแญ แ แแ แฐแจแ แจแแแแแก แฐแแฃแแฝแ แฐแจแ แ แฐแจแ แจแแแแแแ แต แแฐแ (แปแแแ ) แฅแ แญแ แแณแธแแ แจแแแญแ แต แณแญแแณแ แแตแแญแต แแแแแฑแ แฐแแแฟแแข
แฐแแ แจแแฐแฃแธแ แจแตแแ แ แแตแฎแฝ แแแตแแธแ แแธแ?
- แ แณแญแ แญ แฐแ แแแตแฃ
- แ แณแญแ แญ แฐแ แแแต แแญแ แจแตแจแแ แฃ แจแแฐแแ แชแซ แฅแ แฐแซแซแฅ แแแต (development)แฃ
- แจแตแแญแต แแฎแแญแต แฒแตแฐแแฝ แฃ
- แ แคแฎแตแแต แฅแ แแแฝแ แฅแแฐแแ แฐแแแฟแแข
แตแแ แแ แ แ แฒแต แ แ แฃ แฉแแจแญแฒแฒ แดแญแแแ แแ แแต แแญ แญแฐแฃแ แจแฐแฃแ แฒแแ แ แแแซแพแฝ แ แแฅแณแญแต https://talent.Insa.gov.et แ แแแฃแต แฅแตแจ แแแฆแต 30/ 2016 แ/แ แแแแแฅ แฅแแตแตแฝแ แฅแแ แแญแงแแข
แแ แแ แแจแ +251904311833 +251943579970
+251904311837
@TikvahethMagazine
FLOW CONTROL : WHILE LOOP
แแฌ แแณ แจแฃแแแ แตแแ แญแต แจแแ แ แ Python แตแ While loop แฅแแแซแแแข
Stay tuned!
โฑ๏ธ 8 : 00 PM EAT
@python_pioneers
@python_pioneers
แแฌ แแณ แจแฃแแแ แตแแ แญแต แจแแ แ แ Python แตแ While loop แฅแแแซแแแข
Stay tuned!
โฑ๏ธ 8 : 00 PM EAT
@python_pioneers
@python_pioneers
๐1
What is a While Loop?
แจแฐแแฐแ แแแณ แฅแแแต แฅแตแจแแ แตแจแต แ แแญแแ แแตแฅ แแฐแแฐแ แแ loop แ แฐแฐแแแ แจแฎแต แฅแแณแ แญแแฝแแแข แฅแ แ แแญ แจแแแแ แจแตแแแแฝ แฅแแต แ แตแแตแ แ แแญแณแแ แ แต แแ แฅแ แ แแณแแต แแแณแแฝ แ แแแแ แต แแ แแ.
While loop แ Python แ แแตแ block of code specify แจแฐแฐแจแแ condition แฅแแแต แฅแตแจแแ แตแจแต repeatedly(แ แฐแฐแแแ) execute แจแแซแจแ แจ Python flow control แ แญแแต แแแข While loopแ แจแแแ แแแ number of iteration แแแญแณแแ แฃแธแ แแญแ executionแ แธแ on some condition แแญ depend แแแแแฃแธแ blocks of code แแแข
Syntax of While Loop
แจ While loop basic syntax แญแแแ แญแแตแแ:
- condition: แ แแต condition แฅแแแต แแญแ แแฐแต แฅแแฐแแ evaluate แจแแซแจแ expression แแแข
- Code block: แญแ แฐแแ specified แจแแแ condition True แ แแ แแฅแญ execute แจแแฐแจแ แจstatements แตแฅแตแฅ แแแข
Flowchart of a While Loop
1. Evaluate the condition.
2. If the condition is true, execute the code block.
3. Re-evaluate the condition.
4. If the condition is still true, repeat the code block.
5. Continue until the condition becomes false.
to be cont'd...
#WhileLoop
@python_pioneers
@python_pioneers
แจแฐแแฐแ แแแณ แฅแแแต แฅแตแจแแ แตแจแต แ แแญแแ แแตแฅ แแฐแแฐแ แแ loop แ แฐแฐแแแ แจแฎแต แฅแแณแ แญแแฝแแแข แฅแ แ แแญ แจแแแแ แจแตแแแแฝ แฅแแต แ แตแแตแ แ แแญแณแแ แ แต แแ แฅแ แ แแณแแต แแแณแแฝ แ แแแแ แต แแ แแ.
While loop แ Python แ แแตแ block of code specify แจแฐแฐแจแแ condition แฅแแแต แฅแตแจแแ แตแจแต repeatedly(แ แฐแฐแแแ) execute แจแแซแจแ แจ Python flow control แ แญแแต แแแข While loopแ แจแแแ แแแ number of iteration แแแญแณแแ แฃแธแ แแญแ executionแ แธแ on some condition แแญ depend แแแแแฃแธแ blocks of code แแแข
Syntax of While Loop
แจ While loop basic syntax แญแแแ แญแแตแแ:
while condition:
# Code block to be executed
- condition: แ แแต condition แฅแแแต แแญแ แแฐแต แฅแแฐแแ evaluate แจแแซแจแ expression แแแข
- Code block: แญแ แฐแแ specified แจแแแ condition True แ แแ แแฅแญ execute แจแแฐแจแ แจstatements แตแฅแตแฅ แแแข
Flowchart of a While Loop
1. Evaluate the condition.
2. If the condition is true, execute the code block.
3. Re-evaluate the condition.
4. If the condition is still true, repeat the code block.
5. Continue until the condition becomes false.
to be cont'd...
#WhileLoop
@python_pioneers
@python_pioneers
โก1
...cont'd
แแณแ:
แ แแ แแณแ แจแแแจแ program แจ 1 แฅแตแจ 5 แซแ แแฅแฎแฝแ print แจแแซแจแ แแ:
Detailed Explanation
1. Initialization:
2. Condition Check:
3. Body of Loop:
4. Increment:
Increment แแแต แจแ แแตแ variable value แ แแ แซแ แ แ แแแแต แแจแแญ แแแต แแแฃ แ แแญแแ case each time the variable 'i' is being incremented by 1.
5. Re-evaluation: The condition
If you have understood about while loop from the above two posts, answer these questions given below.
#WhileLoop
@python_pioneers
@python_pioneers
แแณแ:
แ แแ แแณแ แจแแแจแ program แจ 1 แฅแตแจ 5 แซแ แแฅแฎแฝแ print แจแแซแจแ แแ:
i = 1
while i <= 5:
print(i)
i += 1 # Increment the value of i by 1
Detailed Explanation
1. Initialization:
i is initialized to 1 แแแตแ i แจแแฃแ variable initial valueแแ แ แแต แ แญแแแแข2. Condition Check:
i <= 5 check แญแฐแจแแ: conditionแก แฅแแแต แจแแ loopแก แญแแฅแแ otherwise loopแก terminate แซแจแแแข3. Body of Loop:
print(i) แจ variable 'i' แ current value print แซแจแแแข4. Increment:
i is incremented by 1 using i += 1.Increment แแแต แจแ แแตแ variable value แ แแ แซแ แ แ แแแแต แแจแแญ แแแต แแแฃ แ แแญแแ case each time the variable 'i' is being incremented by 1.
5. Re-evaluation: The condition
i <= 5 is checked again with the new value of i.If you have understood about while loop from the above two posts, answer these questions given below.
#WhileLoop
@python_pioneers
@python_pioneers
โค1๐1
1. What is the purpose of a while loop in Python?
Anonymous Quiz
29%
A) To iterate over a sequence of elements
68%
B) To execute a block of code repeatedly based on a condition
4%
C) To define a function
0%
D) To break out of a loop
2. What happens if the condition in a while loop is never met?
Anonymous Quiz
29%
A) The loop will run indefinitely
42%
B) The loop will not run at all
13%
C) The loop will skip to the next iteration
17%
D) The loop will exit immediately
3. What is the difference between a while loop and a for loop in Python?
Anonymous Quiz
65%
A) A for loop always runs a specific number of times, and while loop runs until a condition is met
9%
B) A while loop can only iterate over lists, while a for loop can iterate over any iterable object
17%
C) A while loop is more efficient in terms of performance than a for loop
9%
D) A for loop requires a loop variable, while a while loop does not
๐1
4. In a while loop, what purpose does the increment/decrement statement serve?
Anonymous Quiz
11%
A. It increments the loop counter
5%
B. It decrements the loop counter
74%
C. It determines when the loop should terminate
11%
D. It has no effect on the loop
5. How is the condition in a while loop written in Python?
Anonymous Quiz
20%
A. if condition:
68%
B. while condition:
4%
C. until condition:
8%
D. for condition in range:
Comment your answers from now on...
6. What is the output of the following code?
A) 0 1 2
B) 0 1 2 3
C) 1 2 3
D) 0 1
6. What is the output of the following code?
i = 0
while i < 3:
print(i)
i += 1
A) 0 1 2
B) 0 1 2 3
C) 1 2 3
D) 0 1
7. How many times will "Hello, World!" be printed?
A) 6
B) 5
C) 4
D) Infinite
count = 5
while count > 0:
print("Hello, World!")
count -= 1
A) 6
B) 5
C) 4
D) Infinite
8. What will be the value of
A) 10
B) 15
C) 20
D) 5
sum after the execution of the following code?sum = 0
i = 1
while i <= 5:
sum += i
i += 1
A) 10
B) 15
C) 20
D) 5
9. What is the purpose of the following
A) To count up from 1 to 10
B) To count down from 10 to 1
C) To count down from 10 to 0
D) To count up from 0 to 10
while loop?n = 10
while n > 0:
n -= 1
A) To count up from 1 to 10
B) To count down from 10 to 1
C) To count down from 10 to 0
D) To count up from 0 to 10
10. What will be the output of the following code?
A) 0 1 2 3
B) 1 2 3 4
C) 0 1 2 3 4
D) 1 2 3
x = 0
while x < 4:
x += 1
print(x)
A) 0 1 2 3
B) 1 2 3 4
C) 0 1 2 3 4
D) 1 2 3
๐1
แแแฝแแแ แตแแฐแณแตแแฝแ แ แฃแ แฅแแแฐแแแแ!
แ แดแญแแแแ แแญแ แฅแ แจแแ แตแแแต แแแซแต แแ แแญ แ แตแ แแแซแต แจแแแแแแตแ แขแตแฎแตแซ แแแแแฃแต แแแ แ แแซแญ แแแข
แแแซแ แแฝแต!
@python_pioneers
@python_pioneers
แ แดแญแแแแ แแญแ แฅแ แจแแ แตแแแต แแแซแต แแ แแญ แ แตแ แแแซแต แจแแแแแแตแ แขแตแฎแตแซ แแแแแฃแต แแแ แ แแซแญ แแแข
แแแซแ แแฝแต!
@python_pioneers
@python_pioneers
โค2๐1๐1
https://t.me/tapswap_mirror_1_bot?start=r_6163528558 ๐ +2.5k Shares as a first-time gift
๐2
Infinite Loop
While loopแ แตแแ แแ common แจแแ แฝแแญ แขแแญ แจinfinite loop แแแ แญ แแแข แญแ แ infinite loop conditionแก False แแผแ แ แแญแแแ แต แแ แญแแ แซแแข
Example of an infinite loop:
แจแแญ แซแแ แแฎแแซแ "This will print forever" แจแแแแ แ/แแแญ แซแ แแฐแฅ print แซแจแแแข
Breaking Out of a Loop
Infinite Loop avoid แแแจแ "break" statement แแ แแ แฅแแฝแแแแฃ แญแ แ แจแแ condition set แ แญแแ แฅแแแต แ แแแแ แต แแ loopแกแ exit แฅแแตแแจแ แญแจแณแแแข
แจแแญ แซแแ แแฎแแซแ แแแแชแซ แจแฐแแแ แจ 1 แฅแตแจ 10 แซแ แแฅแฎแฝแ print แฅแแฒแซแจแ แขแแแ แจ'i' value 5 แฒแแ แฅแแฒแซแแ แ แตแ-แแแณ แตแแตแแแฅแ แแญ แจ'i' value 5 แฒแแ loopแก แญแแแแข
Using Else with While Loop
Python 'else' clause แจ while loop แแญ แฅแแตแแ แแ แญแแ แณแแข แจ'else' block executed แจแแแแ แจ while loop condition แแฐแต แฒแแ แแแข (i.e., the loop terminates naturally).
แแณแ
...แญแแฅแแ
#WhileLoop
@python_pioneers
@python_pioneers
While loopแ แตแแ แแ common แจแแ แฝแแญ แขแแญ แจinfinite loop แแแ แญ แแแข แญแ แ infinite loop conditionแก False แแผแ แ แแญแแแ แต แแ แญแแ แซแแข
Example of an infinite loop:
while True:
print("This will print forever")
แจแแญ แซแแ แแฎแแซแ "This will print forever" แจแแแแ แ/แแแญ แซแ แแฐแฅ print แซแจแแแข
Breaking Out of a Loop
Infinite Loop avoid แแแจแ "break" statement แแ แแ แฅแแฝแแแแฃ แญแ แ แจแแ condition set แ แญแแ แฅแแแต แ แแแแ แต แแ loopแกแ exit แฅแแตแแจแ แญแจแณแแแข
i = 1
while i <= 10:
print(i)
if i == 5:
break # Exit the loop when i is 5
i += 1
แจแแญ แซแแ แแฎแแซแ แแแแชแซ แจแฐแแแ แจ 1 แฅแตแจ 10 แซแ แแฅแฎแฝแ print แฅแแฒแซแจแ แขแแแ แจ'i' value 5 แฒแแ แฅแแฒแซแแ แ แตแ-แแแณ แตแแตแแแฅแ แแญ แจ'i' value 5 แฒแแ loopแก แญแแแแข
Using Else with While Loop
Python 'else' clause แจ while loop แแญ แฅแแตแแ แแ แญแแ แณแแข แจ'else' block executed แจแแแแ แจ while loop condition แแฐแต แฒแแ แแแข (i.e., the loop terminates naturally).
แแณแ
i = 1
while i <= 5:
print(i)
i += 1
else:
print("Loop has ended")
...แญแแฅแแ
#WhileLoop
@python_pioneers
@python_pioneers
๐4โค1
Common Use Cases
1. Waiting for User Input: แจแแแแแแ data แฅแตแจแแแแ User input แ แฐแฐแแแ แฅแแตแแแ แ แญแจแณแแแข
2. Processing Data Streams: แแจแจแป แแญ แฅแตแจแแแฐแญแต data แจfile แแญแ แจ network stream continuously แฅแแตแแแฅ แญแจแณแแแข
3. Polling: แจแ แแตแ resource status periodically check แฅแแตแแจแ แญแจแณแแแข
แแณแ: User Input
Here's an example where we keep asking the user for a positive number:
แจแแญ แซแแ แแฎแแซแ userแก positive แแฅแญ แฅแแฒแซแตแแฃ repeatedly แญแ แญแแแแฃ แแฅแฉแ แฐแแ print แซแจแแแฃ if the user enters a positive number the loop ends, because the condition becomes false.
...to be continued
#WhileLoop
@python_pioneers
@python_pioneers
1. Waiting for User Input: แจแแแแแแ data แฅแตแจแแแแ User input แ แฐแฐแแแ แฅแแตแแแ แ แญแจแณแแแข
2. Processing Data Streams: แแจแจแป แแญ แฅแตแจแแแฐแญแต data แจfile แแญแ แจ network stream continuously แฅแแตแแแฅ แญแจแณแแแข
3. Polling: แจแ แแตแ resource status periodically check แฅแแตแแจแ แญแจแณแแแข
แแณแ: User Input
Here's an example where we keep asking the user for a positive number:
number = -1
while number < 0:
number = int(input("Enter a positive number: "))
print("You entered: ", number)
แจแแญ แซแแ แแฎแแซแ userแก positive แแฅแญ แฅแแฒแซแตแแฃ repeatedly แญแ แญแแแแฃ แแฅแฉแ แฐแแ print แซแจแแแฃ if the user enters a positive number the loop ends, because the condition becomes false.
...to be continued
#WhileLoop
@python_pioneers
@python_pioneers
๐2