<jupyter_start><jupyter_text>Control flow - the 'grammar' of programing languagesToday we cover if statements, next you'll learn about for loops By the end of the day you'll be able to- create simple if statements- create if statements with multiple conditions- create a sequence of if-else statements   Control flow  Every code can be broken down to pieces like this:- **Instructions**: "Do this; then do that."- **If statements**: "If the condition is true, perform this action; otherwise, do that action."- **For loops**: "Do this action that number of times."- **While loops**: "Keep doing that until this condition is false."**The instructions operate on variables and containers.** Programming is like playing with lego.   By the end of the day you'll be able to- **create simple if statements**- create if statements with multiple conditions- create a sequence of if-else statements<jupyter_code>if condition(s): # stuff after the if is a boolean variable (either true or false)
    # do something
    # you must indent
else:
    # do something else
    # you must indent this as well
# instructions
age_int = 100 # instruction: assign the integer value 18 to age_int

if age_int > 17: # note that the condition is a boolean variable with a value true or false
    print("can vote") # what we print is a string variable
else:
    print("cannot vote") # another string variable
# four instructions: assign values to variables
age_int = 17
check_age_bool = age_int > 17
var1_str = 'can vote'
var2_str = 'cannot vote'

# if-else statement
if check_age_bool: 
    print(var1_str)
else:
    print(var2_str)
    
# you can also change a variable's value in an if statement

age_int = 19

if age_int > 17: 
    can_vote_bool = True
else:
    can_vote_bool = False

print(can_vote_bool)
print('this is outside of the if statement')
# condition/boolean variable can check type, list length, anything really
# and you can do anything inside the if and else parts too
age_int = 99

if type(age_int) == int:
    variable_named_correctly_str = 'yes'
else:
    variable_named_correctly_str = 'no'
    
print(variable_named_correctly_str)<jupyter_output>yes<jupyter_text>Exercise 1Check if the list below has at least 10 elements. If it does, append the string 'yes' to the list. If it does not, append the string 'no' to the list. Test your code by adding elements to my_lst so you explore both conditions (less than or at least 10 elements).<jupyter_code>my_lst = [1, 67, 'whatever', 'etc', 234 , True]

# add your code here<jupyter_output><empty_output><jupyter_text>By the end of the day you'll be able to- create simple if statements- **create if statements with multiple conditions**- create a sequence of if-else statements<jupyter_code># multiple conditions with *and*
# all conditions need to be True

age_int = 100

if (age_int >= 2) and (age_int <= 100): # multiple conditions need to be in parentheses, these are boolean variables  
    print("can walk") # print a string
else:
    print("cannot walk") # print another string
# multiple conditions with *or*
# it is enough if one condition is True

age_int = 101

if (age_int < 2) or (age_int > 100): # multiple conditions need to be in parentheses, these are boolean variables  
    print("cannot walk") # print a string
else:
    print("can walk") # print another string<jupyter_output>cannot walk<jupyter_text>Exercise 2Check if a string contains the vowels 'a' or 'e'. Create a variable called has_a_e_bool and set its value appropriately. Please change the value of the string such that you try words with 'a' and 'e', only an 'a', only 'e', and no 'a' or 'e'. This way you explore all options and test your code.<jupyter_code>my_str = 'hello'<jupyter_output><empty_output><jupyter_text>By the end of the day you'll be able to- create simple if statements- create if statements with multiple conditions- **create a sequence of if-else statements**<jupyter_code>cents_int = 25

if cents_int == 25:
    print("washington")
elif cents_int == 10:
    print("roosevelt")
elif cents_int == 5:
    print("jefferson")
elif cents_int == 1:
    print("lincoln")
else:
    print("not US coin")<jupyter_output>washington<jupyter_text>Exercise 3Let's compare two numbers x_int and y_int. Check if x_int is larger than y_int, else if x_int is equal to y_int, or else if x_int is smaller than y_int. Create a string called compare_str and set its value to either 'larger', 'equal', or 'smaller' as appropriate. Test your code by changing the values of x_int and y_int so you explore all three conditions!<jupyter_code>x_int = 10
y_int = 8<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07892454466608846, 'fraction_numerical': 0.012792714657415438, 'mean_word_length': 4.491666666666666, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 27, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '305709', 'license': 'MIT', 'n_tokens_mistral': 1410, 'n_tokens_neox': 1328, 'n_words': 627, 'path': 'week_1/day_5_if_statements.ipynb', 'repo_name': 'tbw005/workshop-python-2021', 'size': '4612'}