<jupyter_start><jupyter_text>Boolean SectionBelow are only a few examples of how cool Booles can be!But this is only an intro: for much more, read about deMorgan's Law: https://www.ics.uci.edu/~pattis/ICS-31/lectures/simplify/lecture.html<jupyter_code>##String comparisons

"cat" > "dog" # False
# "kitty" > "dog" #True... what do you think is going on here? It's not strig length!
# "ki" > "dog" # Python compares "lexicographically", aka it compares ascii char values
# "cat" > "doggy" #False
# "cat" < "doggy" #True
# "kitty" == "doggy" #False
# given two booleans P and Q
P = True
Q = False
print(type(P)) #<class 'bool'>

P and not Q  # True
# not P and Q  # False
# not (P and Q)  # True: Evaluate parens first...
# (not P) or (not Q)  # True
# Assign str value to a variable
pet = "dog"

# It is NOT the case that pet is "cat"
not pet == "cat"  # True

# pet is "cat" OR "dog"
pet == "cat" or pet == "dog"  # True

# This doesn't work (operators are applied left-to-right; 
# check the type at each step!)
pet == "cat" or "lizard"  # "lizard"<jupyter_output><empty_output><jupyter_text>Conditionals Examples<jupyter_code>oatmeal_temp = 40  # temperature in degrees F

if oatmeal_temp > 120:
    print("This oatmeal is too hot!")
else:
    print("This oatmeal is NOT too hot!")

# too_cold = oatmeal_temp < 70  # a boolean variable
# if too_cold:
#     print("This oatmeal is too cold!")

# This line is outside the block, so is not part of 
# the conditional (it will always be executed)
print("Time for a nap!")
##Demonstrates elif "else if"

if outside_temperature < 60:
    print("Wear a jacket")
elif outside_temperature > 90:
    print("Wear sunscreen")
elif outside_temperature == 72:
    print("Perfect weather!")
else:
    print("Wear a t-shirt")
temperature = 20
#temperature = 50
if temperature < 30:
    print("Wear snow pants")
elif temperature < 60:
    print("Wear a jacket")


# if temperature < 30:
#     print("Wear snow pants")
# if temperature < 60:
#     print("Wear a jacket")

if temperature < 60:
    print("Wear a jacket")
elif temperature < 30:
    print("Wear snow pants")<jupyter_output><empty_output><jupyter_text>Loops and Iteration SectionBelow are only a few examples of how to loop<jupyter_code>import random

# flip a coin until it shows up heads
still_flipping = True  # sentinel
while still_flipping:
    flip = random.randint(0,1)
    if flip == 0:
        flip = "Heads"
    else:
        flip = "Tails"
    print(flip)
    if flip == "Heads":
        still_flipping = False
        
# Run it multiple times to see the results of the random coin flip
for item in range(100): 
    print(item, end = ',')<jupyter_output>0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,<jupyter_text>Execute your own functions from a Jupyter NotebookThis is a simple function, but an amazing concept<jupyter_code>import test_script
##Why doesn't this work? Press shift tab to view the doc string!
test_script.hello_script()<jupyter_output>Hello from the command line CLASS!
It is a good day to script.<jupyter_text>Iterating over files* This is critical for the homework<jupyter_code>with open('data/sample_data.txt') as my_file:  # open the file
    for line in my_file:  # iterate through it
        print(line)       # handle each line
filename = 'data/sample_data.txt'
with open(filename) as file: 
        num_lines = 0
        for line in file: 
            num_lines = num_lines + 1
num_obs = num_lines/3
print(int(num_obs))
    #num_obs = num_lines/3 #this division works for files of this data type: label, number, number...
    #return (round(num_obs))
with open ('data/huskies2016.txt') as my_file:
    for line in my_file:
        print(line)
animals = ['rats', 'slothes', 'moray eels']
for animal in animals:
    print("dogs are great, but have you thought about " + animal + "?\n")

for value in range(1,22):
    print (value)
print("\n")    
numbers = list (range(1,101))
for number in numbers:
    print(number)
print("\n") 
print(min(numbers))
print(max(numbers))
print(sum(numbers))
odd_numbers = list(range(1,21,2))
for number in odd_numbers:
    print(number)
print("\n")

threes = list(range(3,31,3))
for number in threes:
    print(number)
print("\n")<jupyter_output>3
6
9
12
15
18
21
24
27
30
{'fraction_non_alphanumeric': 0.13099754519080561, 'fraction_numerical': 0.059584914081678195, 'mean_word_length': 4.163594470046083, 'pattern_counts': {'":': 1, '<': 28, '<?xml version=': 0, '>': 25, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '624365', 'license': 'MIT', 'n_tokens_mistral': 1806, 'n_tokens_neox': 1621, 'n_words': 507, 'path': 'Lecture_4_Notes.ipynb', 'repo_name': 'ajm1813/Lecture_4_Notes', 'size': '4481'}