FOR LOOP
For loopแ แ Python แจแแแ แแแ แจแแแ line of code แแญแ แฅแแฐ list, tuple, string, range, numbers... แจแแณแฐแ sequence of elements แ แฐแฐแแแ execute แแแจแ แแแข แญแ แฐแแ แ sequenceแก แฅแซแแณแแฑ item แแญ แฐแแณแณแญ operation แฅแแตแแซแแต แญแจแณแแแข
แ Python แจfor loop basic syntax แญแแ แญแแตแแ:
แ syntaxแก แแตแฅ:
- "item" แจแแแ แ แฅแซแแณแแฑ Iteration(แตแแแแฝ) แจsequenceแกแ every item แญแแญแแ(placeholder variable แแแข)
- "sequence" แจแแแ แฐแแ แจแแแญแแ loopแก iterate แจแแซแจแแฃแธแ elements of sequenceแ แแแข
แฅแตแช แจแแญ แซแแแ แแณแฅ แ แแณแ แฅแแจแแฃ แ แแณแแ แฐแแ แจแแ แจแแฅแฎแฝ แตแฅแตแฅ แ แ แฃ แจแแ แ listแก iterate แฅแซแจแ แฅแซแแณแแฑแ แแฅแญ print แจแแซแฐแญแ program แแแแ แฅแแแญแซแแแข
We will learn deeply about lists in the future...
This would output:
...to be continued
#ForLoop
@python_pioneers
@python_pioneers
For loopแ แ Python แจแแแ แแแ แจแแแ line of code แแญแ แฅแแฐ list, tuple, string, range, numbers... แจแแณแฐแ sequence of elements แ แฐแฐแแแ execute แแแจแ แแแข แญแ แฐแแ แ sequenceแก แฅแซแแณแแฑ item แแญ แฐแแณแณแญ operation แฅแแตแแซแแต แญแจแณแแแข
แ Python แจfor loop basic syntax แญแแ แญแแตแแ:
for item in sequence:
# do something with item
แ syntaxแก แแตแฅ:
- "item" แจแแแ แ แฅแซแแณแแฑ Iteration(แตแแแแฝ) แจsequenceแกแ every item แญแแญแแ(placeholder variable แแแข)
- "sequence" แจแแแ แฐแแ แจแแแญแแ loopแก iterate แจแแซแจแแฃแธแ elements of sequenceแ แแแข
แฅแตแช แจแแญ แซแแแ แแณแฅ แ แแณแ แฅแแจแแฃ แ แแณแแ แฐแแ แจแแ แจแแฅแฎแฝ แตแฅแตแฅ แ แ แฃ แจแแ แ listแก iterate แฅแซแจแ แฅแซแแณแแฑแ แแฅแญ print แจแแซแฐแญแ program แแแแ แฅแแแญแซแแแข
We will learn deeply about lists in the future...
numbers = [1, 2, 3, 4, 5]
for num in numbers:
print(num)
This would output:
1
2
3
4
5
...to be continued
#ForLoop
@python_pioneers
@python_pioneers
๐4๐ฅฐ1
... continued
For loopแ แจrange() functionแ แแญ แแ แแ แฅแแฝแแแแฃ แ แแ แฐแแ แจแแ range of numbers แแญ iterate แฅแแจแแแแข
แจ
แจ
- start
This would output:
...to be continued
@python_pioneers
@python_pioneers
@python_pioneers
For loopแ แจrange() functionแ แแญ แแ แแ แฅแแฝแแแแฃ แ แแ แฐแแ แจแแ range of numbers แแญ iterate แฅแแจแแแแข
แจ
range() function Python built-in function แฒแแ sequence of numbers แฅแแตแแแฅแญ แญแจแณแแแข แฅแแ แจfor loop แแญ แฐแ แ
แแ over the sequence of numbers iterate แแตแจแ แฅแแฝแแแแขแจ
range() function syntax แญแแ แญแแตแแแกrange(start, stop, step)
- start
is the starting number of the sequence (optional, default is 0)
- stop is the ending number of the sequence (required)
- step is the difference between each number in the sequence (optional, default is 1)
แแณแ 1: แ range function แจ0-9 แแฅแฎแฝแ แแแแฃแต แจแแแแแก range(9) แแแต แฅแแฝแแแแข
แแณแ 2:
for kutir in range(1, 6):
print(kutir)
This would output:
1
2
3
4
5
...to be continued
@python_pioneers
@python_pioneers
@python_pioneers
๐6๐ฅ1
"You can't go back and change the beginning, but you can start where you are and change the ending."
-C.S. Lewis
แธแธแต แแตแฅ แแแฃแณแฝแ แฅแ แ แแ แแฐ แแ แแฐแ แแแฐแญแแธแ แจแแแฝแแธแแ แแแฎแฝ แซแแแแจแฅ แแฐแฅ แแแ แแแข แแแญ แแ แซแแแ แแแญ แแญ แแแจแณแฝแ แแแ แ แญแ แ แแแแข แแฐ แแ แฐแแแฐแ แจแแแแ(แจแฐแซแแธแแ แตแ แฐแถแฝ) แแแแฅ แ แแฝแแ แแแญ แแ แ แแ แแแจแ แฅแแณแจแ แแแฅ แแแฃแต แฅแแฝแแแแข
แแแซแ แแฝแต!
#Quotes
@python_pioneers
@python_pioneers
-C.S. Lewis
แธแธแต แแตแฅ แแแฃแณแฝแ แฅแ แ แแ แแฐ แแ แแฐแ แแแฐแญแแธแ แจแแแฝแแธแแ แแแฎแฝ แซแแแแจแฅ แแฐแฅ แแแ แแแข แแแญ แแ แซแแแ แแแญ แแญ แแแจแณแฝแ แแแ แ แญแ แ แแแแข แแฐ แแ แฐแแแฐแ แจแแแแ(แจแฐแซแแธแแ แตแ แฐแถแฝ) แแแแฅ แ แแฝแแ แแแญ แแ แ แแ แแแจแ แฅแแณแจแ แแแฅ แแแฃแต แฅแแฝแแแแข
แแแซแ แแฝแต!
#Quotes
@python_pioneers
@python_pioneers
๐ฅ4โค3๐ฏ1
Forwarded from ๐๐๐๐ ๐๐๐
https://t.me/tapswap_mirror_bot?start=r_5685218492
๐ +2.5k Shares as a first-time gift
๐ +2.5k Shares as a first-time gift
๐1๐ฅฐ1
PYTHON PIONEERS
Begin your coding journey with us! Join our Telegram and YouTube channels and start learning programming in Amharic today.
Start now and unlock endless possibilities with us.
Let's code together!
@python_pioneers
@python_pioneers
Begin your coding journey with us! Join our Telegram and YouTube channels and start learning programming in Amharic today.
Start now and unlock endless possibilities with us.
Let's code together!
@python_pioneers
@python_pioneers
๐4โค1๐ฅ1
Python Range Function
Practice Problems
โญ๏ธ
range()
Practice Problems
โญ๏ธ
1. What does the following code snippet do in Python?
for i in range(5): print(i)
for i in range(5): print(i)
Anonymous Quiz
57%
a) Prints numbers from 0 to 4
5%
b) Prints numbers from 1 to 5
23%
c) Prints numbers from 0 to 5
15%
d) Prints numbers from 1 to 4
2. What is the correct syntax for using the range function with a start, end, and step value specified?
Anonymous Quiz
46%
a) range(start, end, step)
19%
b) range(start:end:step)
32%
c) range(start, step, end)
3%
d) range(end, start, step)
3. What is the output of the following code snippet:
for i in range(2, 8, 2): print(i)
for i in range(2, 8, 2): print(i)
Anonymous Quiz
25%
a) 2, 3, 4, 5, 6, 7
69%
b) 2, 4, 6
6%
c) 3, 5, 7
0%
d) 2, 5
๐1
4. In Python, what is the default step value for the range function if not specified?
Anonymous Quiz
61%
a) 1
6%
b) 2
24%
c) 0
9%
d) The step value must always be specified
5. Which of the following statements is true about the range function in Python?
Anonymous Quiz
27%
a) It returns a list containing the specified range of elements
8%
b) It only accepts integer values as arguments
50%
c) It can be used to generate sequences of numbers for iteration
15%
d) It requires the use of a loop to print the values returned by the function.
Python Pioneers: A Beginner's Guide ๐ช๐น
1. What does the following code snippet do in Python?
for i in range(5): print(i)
for i in range(5): print(i)
๐Codes in some of the questions are not correctly indented, do them as they were!
Perceptive:
Two twin boys were raised by an alcoholic father. One grew up to be an alcoholic and when asked what happened, he said โI watched my father."
The other grew up and never drank in his life. When asked what happened, he said โI watched my father."
Two boys, same dad, two different perspectives.
Your perspective in life will determine your destination.
GOOD NIGHT!
#EnglishStories
@python_pioneers
@python_pioneers
Two twin boys were raised by an alcoholic father. One grew up to be an alcoholic and when asked what happened, he said โI watched my father."
The other grew up and never drank in his life. When asked what happened, he said โI watched my father."
Two boys, same dad, two different perspectives.
Your perspective in life will determine your destination.
GOOD NIGHT!
#EnglishStories
@python_pioneers
@python_pioneers
โค5๐2๐ฅฐ1
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