<jupyter_start><jupyter_text>Control Structures A block of programming that analyses variables and chooses a direction in which to go based on given parameters is a **control structure**.The term **flow control** details the direction the program takes (how program logic “flows”). It determines how a computer will respond when given certain conditions and parameters. Some typical structures include:- **If** statements- **For** loops- **Functions**   Boolean operators The Boolean data type (True and False) allows us to use a variety of boolean operators- `==` : equals- `!=` : not equals- `>` : more than- `<` : less than- `>=` : more or equal than- `<=` : less of equal than<jupyter_code># Try changing the variable x and seeing how the boolean results change
a=0

print(a==0)
print(a!=0)
print(a>0)
print(a<0)
print(a>=0)
print(a<=0)
# If needed, you can chain boolean operators
a=3
print (1 < a < 5)
print (2 >= a >= 10)
# Together with the function `if ... else` we can create a simple control flow
# Try changing the value of b, to change output printed
b=0

if (b==0):
    print('The statement is True')
else:
    print('The statement is False')

# Take note. Python is particular that the line after a : is indented with 4 spaces

if True:
    print('This works')
if True:
print("This doesn't")
# if-elif-else
# we can add a sequence of `if`s, `elif`s (else if) and `else` 
# to describe sequential logic flow

val = 88
if val >= 100:
    print('value is equal or greater than 100')
elif val > 10:
    print('value is greater than 10 but less than 100')
else:
    print('value is equal or less than 10')
# Exercise 1
# Try chaging the language to get a different output gretting

greeting = 'Hello fellow Pythonista!'
language = 'Italian'

if language == 'Swedish':
    greeting = 'Hejsan!'
elif language == 'Finnish':
    greeting = 'Latua perkele!'
elif language == 'Spanish':
    greeting = 'Hola!'
elif language == 'German':
    greeting = 'Guten Tag!'

print(greeting)<jupyter_output><empty_output><jupyter_text>For loops We can create a list of items using square brackets `[]`We can then use the `for` function to iterate through all the items in a list.<jupyter_code>names = ['Daniel','Adam','Bob','Charlie']
for name in names:
    print(name)
# Ifs and For loops can be combined to encode complex operations
# Example
# Print out the numbers larger than 10 in the following list

numbers =[2,14,5,35,2,5,99,2,4,51,23,94,8,3,22]
for number in numbers:
    if number>10:
        print(number)<jupyter_output><empty_output><jupyter_text>Functions If we find that we have some logic that requires repeated usage.It often makes sense to encapsulate the logic into a function.<jupyter_code># Task: print the square of each number
# Example of tedious, repeated code
print(1**2)
print(2**2)
print(3**2)
print(4**2)

# Instead lets use a function to reduce repetition
# functions are invoked with the def keyword
def square(x):
    # This function returns the square of number x
    return x**2

for number in [1,2,3,4]:
    print(square(number))
# Elsewhere in my code, if I ever need to square any number again
# I can easily reuse the function

# Task square the number 144

print(square(144))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1062056190182155, 'fraction_numerical': 0.024390243902439025, 'mean_word_length': 4.463743676222597, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 22, 'https://': 0, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '625454', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1029, 'n_tokens_neox': 969, 'n_words': 437, 'path': '3. Control Structures.ipynb', 'repo_name': 'ddanieltan/GA-Intro-To-Python', 'size': '3239'}