<jupyter_start><jupyter_text>Python Flow Control Purpose: This notebook will introduce you to If/Else, For Loops, While Loops, and Try/Except  If/Else<jupyter_code>a = 4
if a == 4:
    print('Yay a is 4')
else:
    print('Ugh a is not 4')<jupyter_output><empty_output><jupyter_text>What, if any, is the difference between the previous line and the next line?<jupyter_code>a = 4
if a == 4:
    print('Yay a is 4')
if a != 4:
    print('Ugh a is not 4')<jupyter_output><empty_output><jupyter_text>Why does this work?<jupyter_code>a = 4
b = 5
if (a == 4) and (b == 5):
    print('A is 4 and B is 5!')
elif (a==4):
    print('A is 4 and B is not 5')
elif (b==5):
    print ('B is 5 and A is not 4')
else:
    print('A is not 4 and B is not 5')<jupyter_output><empty_output><jupyter_text>Complete the code below to write the same thing with only if statements (no elif or else)?<jupyter_code>a = 4
b = 5<jupyter_output><empty_output><jupyter_text>For Loop<jupyter_code>for ind in [1,2,3,4]:
    print(ind*5)<jupyter_output><empty_output><jupyter_text>What is the difference between the previous and this statement?<jupyter_code>for ind in range(4):
    print(ind*5)<jupyter_output><empty_output><jupyter_text>Looping over a string<jupyter_code>for val in 'Cassini':
    print(val)<jupyter_output><empty_output><jupyter_text>But what if you also want the index? Use enumerate!<jupyter_code>for ind, val in enumerate('Cassini'):
    print(str(ind)+' '+str(val))
for ind,val in enumerate([1,2,3,4]):
    print(str(ind)+' '+str(val*5))<jupyter_output><empty_output><jupyter_text>Looping over a dictionary<jupyter_code>dict = {'Artemis':['Moon',2008,2],'Barrel':['Antarctica',2013,1],'Cassini':['Saturn',1997,1]}
print(dict.keys())
dict = {'Artemis':['Moon',2008,2],'Barrel':['Antarctica',2013,1],'Cassini':['Saturn',1997,1]}
for mission in dict.keys():
    print(mission)
    print('Location: '+dict[mission][0])
    print('Launch: '+str(dict[mission][1]))
    print('Number of Spacecraft: '+str(dict[mission][2]))
    print('--------------------')
    print('\n')<jupyter_output><empty_output><jupyter_text>You can also loop over multiple nested items at once<jupyter_code>lis = [[1,'a'],[2,'b'],[3,'c'],[4,'d']]
for num, let in lis:
    print(str(num)+' '+let)<jupyter_output><empty_output><jupyter_text>While Loop Conditional<jupyter_code>val = 5
while val < 20:
    print('Value is: '+str(val))
    val += 2
import datetime
import time
timeIn10 = datetime.datetime.now()+datetime.timedelta(seconds=10)
while datetime.datetime.now() < timeIn10:
    print('Waiting')
    time.sleep(1)<jupyter_output><empty_output><jupyter_text>Be careful to not create infinite loops Be careful to track the variable that has the conditional statement  Try Except Error Handling<jupyter_code>a = 5
b = 25
try:
    c = a/b
    print(c)
except ZeroDivisionError:
    print("Cannot Divide by 0")
except:
    print("Something else went wrong")
    
a = 5
b = 0
try:
    c = a/b
    print(c)
except ZeroDivisionError:
    print("Cannot Divide by 0")
except:
    print("Something else went wrong")<jupyter_output><empty_output><jupyter_text>Why is the above better than just letting the error flag?<jupyter_code>a = 5
b = 0
c = a/b
print(c)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15396482567108918, 'fraction_numerical': 0.029003394014193152, 'mean_word_length': 5.369351669941061, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 53, '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': '13', 'dir': 'jupyter-structured-clean-dedup', 'id': '556427', 'license': 'CC-BY-4.0', 'n_tokens_mistral': 1283, 'n_tokens_neox': 1189, 'n_words': 311, 'path': '06_08-Tuesday/PythonIntro_flowctrl.ipynb', 'repo_name': 'abbyazari/ASSURE-REU', 'size': '3241'}