<jupyter_start><jupyter_text>Intro to Python part 1**Attendance code: 8189**<jupyter_code># Print "hello, world!"

print('hello world')
print(3490)
print('hi there', 999)
# Declaring variables

a = 12
b = 3.14159
c = "hi there!"

print(a)
print(a + 10)
print(c)

#fstring or formatted string
print(f'the value of a + b is {a + b}')
print(f'These are curly braces {{}}')
a = 'hello,'
b = 'world!'
c = 'my favorite number is ' #string
d = 3490                    #integer

print(a + b)
#print(c + d) - gives error
#int() converts anything to an int
#str() converts anything to a string

print(c + str(d))
a = 12
b = a

a = 'hi there'

b = 38
a = True
b = False   # case matters

x = 10 > 5  # x holds Boolean type

print(x)

print(30 < 40)

print("aardvark" > "zebra")   # dictionary order

print(4 != 3)
print(4 == 4)
print(4 >= 4)
print(4 <= 4)

a = 12
b = 5

if a > 10 and b < 10:
    print("success!")

if a > 10 or b > 10:
    print("success!")
#if statements
#no curly braces - indentations (whitespace) anything under the indentation is in the condition

if 10 > 5:
    print('10 is still greater than 5, thankfully')
    print('This happens, too')

elif 5 < 10:
    print('Something more sensible...')
else:
    print('Something must be horribly wrong with the universe!')

print('And this happens unconditionally')
#While loops

i = 0

while i < 5:
    print(f'is is now {i}')
    i += 1 #i = i + 1
# For loops
# These operate on iterables, like for-in or for-of
# This style: for(i = 0; i < 10; i++) doesnt exist in Python
# This style: for(i = 5; i < 10; i+=3) doesnt exist in Python
# Counting from 0-4:

for i in range(4): #range is bui;t in iterator for walking through a range
    print(i)

print()


# specify start and end and step
#
#          start end  step
#              |  |   |
for i in range(5, 20, 2):
    print(i)

print()

# print numbers from 10 to 0 (inclusive), only even numbers
for i in range(10,-1,-2):
    print(i)
#For loops work on any iterator
for c in 'hello':
    print(c)
# Gets index and value at the same time
for i, c in enumerate('hello'):
    print(f'The character at index {i} is {c}')

#Otherwise, we'd have to do something like this

s = 'hello'
for i in range(len(s)): #len gets the length of a string or array
    print(f'the character at index {i} is {s[i]}') #square bracket array notation
# Functions

#Make a function 'my_function' that takes no arugments
def my_function():
    print('Hello')
    print('Hello, again')

#Call it!
my_function()
def print_num(n):
    print(n)

print_num(12)

def add_nums(a, b):
    sum = a + b
    return sum

r = add_nums(12, 36)

print(r)
# Scoping rules:
#
# The scope of a variable is the scope in which you first use it
# But you can use a variable in local scope that "hides" something at global scope
#
# You can override scope with "global" and "nonlocal" keywords

def add_10(x):  # copy the argument to x, as if by assignment with =
    # x is local scope, local to add_10()
    x = x + 10   #x += 10, same thing

a = 50
add_10(a)

print(a)  # 50
def add_10(x):
    return x + 10

a = 50
print(add_10(a))

print(add_10(100))<jupyter_output>60
110
{'fraction_non_alphanumeric': 0.12758510976773782, 'fraction_numerical': 0.04072542157174674, 'mean_word_length': 3.2601626016260163, 'pattern_counts': {'":': 0, '<': 11, '<?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': '334271', 'license': 'MIT', 'n_tokens_mistral': 1243, 'n_tokens_neox': 1130, 'n_words': 458, 'path': 'CS42_Fundamentals_M1_Python_1.ipynb', 'repo_name': 'juancaruizc/Fundamentals_M1_Python_1', 'size': '3143'}