<jupyter_start><jupyter_text>Control Structures Flow of Control* Order in which the program's code execute.* 3 Basic types    * Sequential        * Top to bottom        * One line after another    * Selection        * Used for decisions            * if            * if - elif - else    * Repetition        * Used for looping            * for            * while Structure TheoremAs the structure theorem (also called the Böhm-Jacopini theorem) states, if a problem can be solved efficiently with a program, it can be solved using these three structures, sequential, selection and repetiion. Some problems are intractable, meaning there is no efficient algorithm to solve them, thus the necessary distinction of "if a problem can be solved efficiently." If that intrigues you, you can check out Complexity Theory, that is beyond the scope this course.  For Loops* Used for iterating over a sequence* Iterate over a range, loop, tuple, dictionary, set or a string* Repeat a fixed number of times![Loop] (./for-loop.png) When to use For Loops?* You know the number of times you want to execute the loop* e.g:    * Add the values in a list    * Update list values    * Search a value in a list<jupyter_code>veggies = ['artichoke', 'cucumber', 'green beans']
for v in veggies:
    print(v)

s ="Looping"
for g in s:
    print(g)<jupyter_output><empty_output><jupyter_text>Definite for loops* Uses `range()` function*<jupyter_code>help(range)
for x in range(4):
    print(x)
for y in range(2, 5):
    print (y)
for countByFive in range(10, 51, 5):
    print(countByFive)<jupyter_output><empty_output><jupyter_text>While Loops* Executed while a condition is True> Note: Watch out for Infinite Loops* Ensure that the condition becomes false to stop the execution.<jupyter_code>x = 0
while x < 10 : #condition
    print (x)     
    x += 1
x = 10
while x <= 50:
    print(x)
    x = x + 5
point = 10, 20, 30
x, y, z = point
print(x,  y , z)


x, y = 0, 1
while x < 10:
    print(x)
    x, y  = y, x+y<jupyter_output><empty_output><jupyter_text>Sentinel Value* Sentinel Values are variables or values used to indicate a state* In programming, a sentinel value is used to terminate a condition, typically a loop<jupyter_code>MIN_AGE = 1
MAX_AGE = 101
EXIT_VALUE = -1 # Declare Sentinal Value
age = 0
ageList =[]

while (age != EXIT_VALUE): #enter the loop when age != -1
    added = False
    while added == False:
        age = int(input(f"Enter the age between {MIN_AGE} & {MAX_AGE}. To exit, enter {EXIT_VALUE} " ))
        if(age == EXIT_VALUE):
            print("You chose to exit the program. Thank You!!")
            break # breaks the inner loop
        elif MIN_AGE < age < MAX_AGE:
            ageList.append(age)
            added = True

for i in ageList: 
    print(i)    

MIN_AGE = 1
MAX_AGE = 101
EXIT_VALUE = -1 # Declare Sentinal Value
age = 0

while (age != EXIT_VALUE):
    age = int(input(f"Enter the age between {MIN_AGE} & {MAX_AGE}. To exit, enter {EXIT_VALUE} " ))
    if(age == EXIT_VALUE):
        print("You chose to exit the program. Thank You!!")
        pass
    elif MIN_AGE < age < MAX_AGE:
        print(age)<jupyter_output><empty_output><jupyter_text>Exit Strategy `break`* The `break` statement terminates the current loop* Use break condition when an external condition triggers requiring to break the loop.  `continue`* Continues with the next cycle of the nearest enclosing loop. `pass`* Is a null operation - when it is executed nothing happens. * Useful as a placeholder when a statement is required syntactically, but no code needs to be executed. * Helpful while defining classes or functions.<jupyter_code>counter = 2
while counter <= 20:
    for x in range(2, counter):
        if counter % x == 0: 
            print(f'{counter} is not a prime number')
            break
    else:
        print(f'{counter} is prime number')   
        
    counter = counter + 1

#print even numbers
counter = -1
while counter <= 20:
        counter = counter + 1
        if counter % x == 0: 
            print(f'{counter} is even number')
            continue
    
        print(f'{counter} is odd number')<jupyter_output>0 is even number
1 is odd number
2 is even number
3 is odd number
4 is even number
5 is odd number
6 is even number
7 is odd number
8 is even number
9 is odd number
10 is even number
11 is odd number
12 is even number
13 is odd number
14 is even number
15 is odd number
16 is even number
17 is odd number
18 is even number
19 is odd number
20 is even number
21 is odd number<jupyter_text>--- Debugging in Python ---  Assignments: Due Date: 23rd Feb Topic 1: Basic for Loops  Topic 2: Input Validation while Loops Topic 3: Exiting While Loop        * Same as Topic 2 assignent         * Need a exit condition Topic 4: Debugging in Python --- Classwork (Group)* Calculate federal income tax based on the income brackets    * https://taxfoundation.org/2020-tax-brackets/    * To keep it simple, only calculate for 10%, 12% and 22% for Single & Married Individuals fiing Joint    * You should accept the inputs from the user.    * Display the income tax to be paid for the income. * You should continue to prompt to accept the input till the user requests to quit the program. * Handle Exceptions<jupyter_code>def calculate_tax(income, status):
    if(income <= 9875 and status  =='single') or (income <= 19750 and status == 'married'):
        return 0.1
    elif (9876 < income <= 40125 and status  =='single') or (19751<= income <= 80250 and status == 'married'): 
        return 0.12
    else :
        return 0.22


if __name__ == '__main__':
    SENTINAL_VALUE = -1
    income = 0
    tax_amount = 0
    while income != SENTINAL_VALUE:
        income = int(input('Income Please, Enter -1 to exit '))
        if(income == SENTINAL_VALUE): 
            break
        status = input('single or married ')        
        tax_amount = income * calculate_tax(income, status)    
        print(f'Your tax amount is : {tax_amount}')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08415264122646225, 'fraction_numerical': 0.02382936177303783, 'mean_word_length': 3.0227882037533513, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 25, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '79765', 'license': 'MIT', 'n_tokens_mistral': 1898, 'n_tokens_neox': 1753, 'n_words': 784, 'path': 'Module05/topic_notes.ipynb', 'repo_name': 'geiyer/cis189-python', 'size': '6001'}