<jupyter_start><jupyter_text><div style="display: grid;  grid-template-columns: auto auto auto;  background-color: AF96F3;  padding: = 7px;            width:100%;">  <div style="background-color: rgba(255, 255, 255, 0.8);  border: 1px solid rgba(0, 0, 0, 0.8);  padding: 10px 10px 20px;  display:flex; justify-content: space-between;">Lecture 08: Loops in PythonDate: 07/05/2021  <div style="background-color: rgba(255, 255, 255, 0.8);  border: 1px solid rgba(0, 0, 0, 0.8);  padding: 10px;  font-size: 16px;text-align: left;">Author: <NAME>  <div style="background-color: rgba(255, 255, 255, 0.8);  border: 1px solid rgba(0, 0, 0, 0.8);  padding: 0px;  font-size: 14px; display:flex; justify-content: space-between;">      Email: <EMAIL>      Telegram: @javadebadi1990      GitHub: javadebadi     <div style="background-color: rgba(255, 255, 255, 0.8);  border: 1px solid rgba(0, 0, 0, 0.8);  padding: 10px;  font-size: 14px;              text-align: left;">      Table of Contents    8.1 Flowchart with a loop    8.2 range        8.3 for loop                            8.3.1 enumerate                8.4 break and continue            8.4.1 break        8.4.2 continue        8.5 pass statements    8.6 Anonymous for loop variable       Expected time to complete this notebook: 1 hour  8.1 Flowchart with a loop<jupyter_code># print positive integers smaller than given input

number = int(input("Please enter a positive integer:"))

while number > 0:
    print(number, end=" ")
    number -= 1<jupyter_output>Please enter a positive integer:10
10 9 8 7 6 5 4 3 2 1<jupyter_text>8.2 range function<jupyter_code>range(10)  # returns a range iterable for numbers from 0 (included) to 10 (excluded)
# iterable
[*range(10)]
[*range(5, 10)] # returns a range iterable for numbers from 5 (included) to 10 (excluded)
# returns a range iterable for numbers from 5 (included) to 10 (excluded) with steps of 2
[*range(0, 10, 2)]
# returns a range iterable for numbers from -100 (included) to -50 (excluded) with steps of 10
[*range(-100, -50, 10)]
# returns a range iterable for numbers from -100 (included) to -50 (excluded) with steps of -10
[*range(-100, -50, -10)]
# returns a range iterable for numbers from -50 (included) to -100 (excluded) with steps of -10
[*range(-50, -100, -10)]<jupyter_output><empty_output><jupyter_text>for **iterable**s in Python we can do iterations and we can give them to functions which take iterables as argumetns such as `sum`<jupyter_code>sum([1, 2, 3])
sum(range(4))<jupyter_output><empty_output><jupyter_text>8.3 for loop In python we use `for` keyword to write for loops.```Pythonfor  in :    process 1    process 2    process 3```<jupyter_code>for item in range(10):
    print(item**2, end=", ")
scientists = ["Einstein", "Newton", "Tukey", "Khayyam"]

for scientist in scientists:
    print("Hi " + scientist)
scientists = ["Einstein", "Newton", "Tukey", "Khayyam"]

for index in range(len(scientists)):
    print("Hi " + scientists[index])<jupyter_output>Hi Einstein
Hi Newton
Hi Tukey
Hi Khayyam<jupyter_text>8.3.1 enumerate function<jupyter_code>[*enumerate(scientists)]
for index, scientist in enumerate(scientists):
    print("scientist at index " + str(index) + " is " + scientist)<jupyter_output>scientist at index 0 is Einstein
scientist at index 1 is Newton
scientist at index 2 is Tukey
scientist at index 3 is Khayyam<jupyter_text>8.4 break and continue Python has to keywords `break` and `continue` which can be used insided loop.     When Python reaches to `break` inside a loop, it immediately gets out the loop.      When Python reaches to `continue` inside a loop, it stops executing the lines below and starts the next iteration in the loop.  8.4.1 break<jupyter_code>for number in range(10):
    print(number, end=", ")
    if number % 9 == 7:
        if number % 9 == 8:
            break<jupyter_output>0, 1, 2, 3, 4, 5, 6, 7, 8, 9,<jupyter_text>8.4.2 continue<jupyter_code>for i in range(10):
    if i % 2 == 0:
        print("Even number occured:", str(i))
        continue
    print("Loop number = "+ str(i))
    print("-----------------------")<jupyter_output>Even number occured: 0
Loop number = 1
-----------------------
Even number occured: 2
Loop number = 3
-----------------------
Even number occured: 4
Loop number = 5
-----------------------
Even number occured: 6
Loop number = 7
-----------------------
Even number occured: 8
Loop number = 9
-----------------------<jupyter_text>8.5 pass statements Python has a special keyworkd `pass`which means to do nothing<jupyter_code>for i in range(10):
    pass  # complete this line of code later
def my_function():
    pass  # implement this function later<jupyter_output><empty_output><jupyter_text>8.6 Anonymous for loop variable<jupyter_code>for _ in range(10):
    print("hello")<jupyter_output>hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
{'fraction_non_alphanumeric': 0.14130211542411172, 'fraction_numerical': 0.056479769973300474, 'mean_word_length': 3.411231884057971, 'pattern_counts': {'":': 0, '<': 38, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '620281', 'license': 'MIT', 'n_tokens_mistral': 1803, 'n_tokens_neox': 1555, 'n_words': 573, 'path': 'Lecture-08-Loops-in-Python.ipynb', 'repo_name': 'javadebadi/python-course', 'size': '4893'}