<jupyter_start><jupyter_text>Workflows, a.k.a. programming  Loops<jupyter_code>animals = ["lion", "tiger", "crocodile", "vulture", "hippo"]
len(animals)
animals[2:]
for creature in animals:
    print(creature)<jupyter_output>lion
tiger
crocodile
vulture
hippo<jupyter_text>The above loop is equivalent to me typing:<jupyter_code>creature = "lion"
print(creature)
creature = "tiger"
print(creature)
# ...
creature = "hippo"
print(creature)
for animal in animals:
    print(animal)
for creature in animals:
    print(creature)
    print("still in the loop!")
print("not in loop any longer")<jupyter_output>lion
still in the loop!
tiger
still in the loop!
crocodile
still in the loop!
vulture
still in the loop!
hippo
still in the loop!
not in loop any longer<jupyter_text>Need to be consistent in indentation!<jupyter_code>for creature in animals:
    print(creature)
        print("still in the loop!")
print("not in loop any longer")
for creature in animals:
    print(creature)
for creature in animals:
    print(creature + ", ")
for creature in animals:
    print(creature + ", ", end="")
for creature in animals:
    print(creature, end=", ")
", ".join(animals)<jupyter_output><empty_output><jupyter_text>Conditional statements<jupyter_code>for i in animals:
    if(i != "hippo"):
        print(i, end=', ')
    else:
        print(i)
a = 5
if a < 0:
    print("a is negative")
elif a == 0:
    print("a is zero")
else:
    print("a is positive")
print("outside of if statement")
a = -5
if a < 0:
    print("a is negative")
elif a == 0:
    print("a is zero")
else:
    print("a is positive")
print("outside of if statement")
a = 0
if a < 0:
    print("a is negative")
elif a == 0:
    print("a is zero")
else:
    print("a is positive")
print("outside of if statement")<jupyter_output>a is zero
outside of if statement<jupyter_text>Again: indentation matters!<jupyter_code>a = 0
if a < 0:
    print("a is negative")
elif a == 0:
    print("a is zero")
else:
    print("a is positive")
    print("outside of if statement")<jupyter_output>a is zero<jupyter_text>Functions<jupyter_code>def add_two_numbers(a, b):
    return a+b
add_two_numbers(3, 5)
add_two_numbers()
add_two_numbers(4, -17)<jupyter_output><empty_output><jupyter_text>Challenge: write an absolute value function<jupyter_code>abs(5)
abs(-5)
abs(-17)
abs(25)
def absolute_value(n): 
    if(n < 0):
        return n*-1 
    else:
        return n
def absolute_value(n):
    if n < 0:
        return -n
    else:
        return n
def absolute(x):
    if x < 0:
        return (x - 2*x)
    if x == 0:
        return 0
    if x > 0:
        return x
def absolute(x):
    if x < 0:
        return x - 2*x
    elif x == 0:
        return 0
    elif x > 0:
        return x
def absolute(x):
    if x < 0:
        return_value = x - 2*x
    if x == 0:
        return_value = 0
    if x > 0:
        return_value = x
    return return_value<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12397540983606557, 'fraction_numerical': 0.014344262295081968, 'mean_word_length': 3.3651266766020864, 'pattern_counts': {'":': 0, '<': 34, '<?xml version=': 0, '>': 28, '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': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '571158', 'license': 'CC-BY-4.0', 'n_tokens_mistral': 1118, 'n_tokens_neox': 1058, 'n_words': 323, 'path': 'files/07-gregs_workflows-thurs10-30am.ipynb', 'repo_name': 'UCSBCarpentry/2021-10-19-ucsb-python-online', 'size': '2928'}