<jupyter_start><jupyter_text>Table of Contents<jupyter_code># 8 mins
# in basics
# we are able to create simple python code
# that will execute from top to bottom
# We will not begin the section on control flow
# have the computer exectue code depending on condition
# how to have the computer repeditly exectue code
# we use the if/elif/else to provide
# a series of conditionals for code to execute
# talk about code structure and syntax as you type below
# python uses indentation go group lines of code
# as opposed to other languages where it is optional for readability
# indentation 'blocks'
# : colon signals indentiaon block start
x = 10
if x > 0:
    print('Value is greater than 0')
x = 10
if x > 0:
    print('Value is greater than 0')
    print('still in the same block')
print('out of block ans will always print')
x = -10 # chagne to neg number
if x > 0:
    print('Value is greater than 0')
    print('still in the same block')
print('out of block ans will always print')
# by convention use 4 spaces (not a tab, but tabs work too)
# that's not the point, as long as the number of spaces is the same
# it will be considered part of that block
# PEP-8 uses 4 spaces
x = 10
if x > 0:
    print('Value is greater than 0')
elif x == 0:
    print('Value is equal to 0')
else:
    print('Value is negative')
x = 10
if x > 0:
    print('Value is greater than 0')
elif x == 0:
    print('Value is equal to 0')
else:
    print('Value is negative')
print('this will always run')
# as many elif statements
# and only at most 1 else
# the else must always come last
# show 2 if statments

# show nested if statements of above code
# False, 0, None, "", and empty containers are treated as False
# else is True
x = []
if x:
    print(1)
else:
    print(0)
x = 0
if x:
    print(1)
else:
    print(0)
x = None
if x:
    print(1)
else:
    print(0)
x = [13]
if x:
    print(1)
else:
    print(0)
# but you should really write something like this
# since you are really testing for length >= 1
x = [13]
if len(x) >= 1:
    print(1)
else:
    print(0)
# test for None value
# by using
if x is None:
    print(1)
else:
    print(0)
# don't write this
# this may have unexpected consequences
if x == None:
    print(1)
else:
    print(0)<jupyter_output>0
{'fraction_non_alphanumeric': 0.08840515326521546, 'fraction_numerical': 0.023545091070635273, 'mean_word_length': 3.3474903474903477, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 11, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '177242', 'license': 'CC-BY-4.0', 'n_tokens_mistral': 753, 'n_tokens_neox': 709, 'n_words': 359, 'path': 'notebooks/basics_2/01 - If statements.ipynb', 'repo_name': 'chendaniely/2017-10-26-mckinsey', 'size': '2251'}