<jupyter_start><jupyter_text>██████╗ ██╗   ██╗████████╗██╗  ██╗ ██████╗ ███╗   ██╗██╔══██╗╚██╗ ██╔╝╚══██╔══╝██║  ██║██╔═══██╗████╗  ██║██████╔╝ ╚████╔╝    ██║   ███████║██║   ██║██╔██╗ ██║██╔═══╝   ╚██╔╝     ██║   ██╔══██║██║   ██║██║╚██╗██║██║        ██║      ██║   ██║  ██║╚██████╔╝██║ ╚████║╚═╝        ╚═╝      ╚═╝   ╚═╝  ╚═╝ ╚═════╝ ╚═╝  ╚═══╝<jupyter_code># This is a single cell of a Jupyter notebook running the iPython (interactrive Python kernel) kernel
# To run this cell, click it so it is highlighted, then simply press [ SHIFT + ENTER ] simultaneously (i.e. holding down SHIFT, then pressing ENTER)
# <------- Did you see a number appeared in the brackets to the left of the first cell? Press [ SHIFT + ENTER ] again...  
# <------------- See how that number increases? 
# ------------------> Press [ SHIFT + ENTER ]
# <--------------------- That's how we can tell that a cell has been run and the order in which they've been run! 
# ----------------------------->  Press [ SHIFT + ENTER ] 
# But why is there a "#" at the start of each line of code?  
# ------------------------------------> Press [ SHIFT + ENTER ]
# Let's see what happens when there isn't a "#"...
# -----------> Press [ SHIFT + ENTER ]<jupyter_output><empty_output><jupyter_text>Uh oh! There was a syntax error! Basically, this means that the iPython kernel doesn't understand what you're saying because you tried to run written English as a programming language... Whenever you run code ~through~ the iPython kernel, it has to have the correct "Pythonic" syntax.You should be able to see a small "^" or caret symbol in the error above at the point iPython didn't understand you (this is very helpful for debugging)Then why does running this cell not result in an error?! That's because it is a "raw" cell. You can change it to "code" or "markdown" (formatted text commonly use to write mathematical equations) using the dopdown box above.Cycle through the options for the above cell , press [ SHIFT + ENTER] and see what happens...<jupyter_code># Having a "#" at the start of a line of python code, turns it into a comment, widely used for code annotation 
# ----> Press [ SHIFT + ENTER ] (This is the last time i'll tell you to do this, but you've got the hang of it!)
""" Note: Triple quotes can be used for multi-line comments (or text art...) 
 ____             __     __                                       __     
/\  _`\          /\ \__ /\ \                        __           /\ \    
\ \ \L\ \ __  __ \ \ ,_\\ \ \___      ___     ___  /\_\     __   \ \ \      
 \ \ ,__//\ \/\ \ \ \ \/ \ \  _ `\   / __`\ /' _ `\\/\ \   /'___\ \ \ \  
  \ \ \/ \ \ \_\ \ \ \ \_ \ \ \ \ \ /\ \L\ \/\ \/\ \\ \ \ /\ \__/  \ \_\ 
   \ \_\  \/`____ \ \ \__\ \ \_\ \_\\ \____/\ \_\ \_\\ \_\\ \____\  \/\_\
    \/_/   `/___/> \ \/__/  \/_/\/_/ \/___/  \/_/\/_/ \/_/ \/____/   \/_/
              /\___/                                                             
              \/__/     
"""
# using a hash is also useful to prevent a line of code from running (called "commenting out" a line of code).
# e.g. Run the below cell and view the output beneath the cell

var_a = 12
#var_a = 15
var_b = 3
var_c = var_a / var_b
print(var_c)
# The same code is copied below...
# Delete the hash on line 4 (show line numbers using [SHIFT + L]), then run this cell 

var_a = 12
var_a = 15
var_b = 3
var_c = var_a / var_b
print(var_c)
# Congrats! You just ran your first cells of Python code! 
# Did you notice that the value of the variable "var_a" was overwritten when you set it twice? 
### TRY IT YOURSELF ACTIVITY ###
# In one line, subtract var_b from var_a and and multiply it by 10 to the power of var_c and then print the results 
10**var_c

### HIDDEN ANSWER ###
print((var_a-var_b)*(10**var_c))<jupyter_output>1200000.0<jupyter_text>***<jupyter_code>### CODEBREAK ###
# If you want to learn more about how these variables are stored and manipulated on your computer watch the video below, the whole seriese is excellent and well worth binge-watching!
from IPython.display import YouTubeVideo
YouTubeVideo('1GSjbWt0c9M', width=800, height=300)
# E.g. what does var_a look like in 8-bit bianry code? e.g. https://www.h-schmidt.net/FloatConverter/IEEE754.html
'{0:08b}'.format(var_a)<jupyter_output><empty_output><jupyter_text>***<jupyter_code># The values we created above will persist within the notebook (until they are overwritten or deleted)
print("These variables still return values:", var_a, var_b, var_c)
# f-string formatting can be used to display these values with more context (by mixing string text and varaible values)
# NOTE: f-strings need an f at the start and curly brackets around the variable names, which will be inserted into the string at that position
print(f"These variables still return values: var_a = {var_a}, var_b = {var_b}, var_c = {var_c}")
# String outputs can be displayed on separate lines using [ backslash + n ] or "\n" 
print(f"These variables still return values: \nvar_a = {var_a}\nvar_b = {var_b}\nvar_c = {var_c}") # NOTE: f-strings need an f at the start and curly brackets around the variable names
### TRY IT YOURSELF ACTIVITY ###
# Make your own f-string, mixing a variable value with a string and print the results! 


# But what is a string anyway?
myString = "I'm a string!"
print(myString)
# A string is a data type in Python
# We can check the type of any variable using
type(myString)
#What does this look like in bianry code?
print(" ".join(f"{ord(i):08b}" for i in myString))
# A ~string~ is a STRING of BYTES!!! 
# There are qyite a few other data types in Python....
# Python is easier than some other languages because it implicity understands types
# What it the type of variables a?
print("var_a is a       String         (str)?  ---->", type(var_a) == str)
print("var_a is a    Floating Point   (float)? ---->", type(var_a) == float)
print("var_a is an      Integer        (int)?  ---->", type(var_a) == int)
# Becuase type(var_a) == int is True, then var_a is an Integer, i.e. a whole number with no decimal points

# We can convert "var_a" into a floating point number (giving it some decimals):
float(var_a)
# We can also convert "var_a" into a string (so we can combine it with other strings without using f-strings)
myString + " ABC, " + str(var_a) + "3, Do Re Mi"
# We saw another data type retuned from above, True / False which is a type called "boolean" This data type is named after English mathemetitian George Boole
# Boole gave birth to Boolean (True/False) Algebra and thus the 0s and 1s at the heart of computing
# Many processes in a program can be broken down into boolean logic, e.g. 
print(var_b < 10)
# We can use if / else statements to print statementes conditional on this boolean logic:
if var_b < 10:
    print("var_b is less than 10")
else:
    print("var_b is greater than (or equal to) 10")
# We can expand this to modify the the value of var_b based on it's current value
if var_b < 10:
    print("var_b is less than 10... adding 10 to var_b")
    var_b = var_b + 10
    print("\nNow var_b = ", var_b)
else:
    print("var_b is greater than (or equal to) 10... subtracting 10 from varb_b")
    var_b = var_b - 10
    print("\nNow var_b =", var_b)
# Run the cell above a few times and follow the logic of the if/else statement

# We can now run this if / else statement on the condition that (i.e. while) another statment is true:
i = 0
while i < 50:
    if var_b < 10:
        var_b = var_b + 10
        print("i = ", i, ", var_b = ", var_b)
    else:
        var_b = var_b - 10
        print("i = ", i, ", var_b = ", var_b)
    i = i + 1
# Then we can turn this into a function
def my_func(i,var_b):
    while i < 50:
        if var_b < 10:
            var_b = var_b + 10
            print("i = ", i, ", var_b = ", var_b)
        else:
            var_b = var_b - 10
            print("i = ", i, ", var_b = ", var_b)
        i = i + 1
# And run the function with a new value of i
my_func(30,var_b)
# or a new value of both i and var_b:
my_func(44,1)
# Another data type is lists:
my_list = ["list item 1", "list item 2", "list item 3", "list item 4", "list item 5"]
# Items within the list can be retrieved (i.e. subsetted) starting from 0
my_list[0]
# Multiple items can be subset
my_list[2:-1]
# Similarly, values can be kept alongside keys within a dictionary
my_dict = {
    "keyA":"dict value 1",
    "keyB":"dict value 2",
    "keyC":"dict value 3",
    "keyD":"dict value 4"}
# Keys can be used to the items within the dictionary 
my_dict["keyA"]
# for loops can be used to iterate through items in lists and keys in dictionaries
for i in my_list:
    print(i)
for key in my_dict:
    print(key)
    print(my_dict[key])
# or simnply, the keys and values can be called separately
# this is more efficient than pulling the value from the dictionary each time it is called
for key, value in my_dict.items():
    print(value)
# items in lists can also be expressed in a single line to create a modified list:
["modified " + i[-6:] for i in my_list]
### TRY IT YOURSELF ACTIVITY ###
# Create your own dictionary and for loop to print out the text from the first 3 lines of your faviourite song!
my_song = {}
my_song = {"lyrics1":"I'm just a poor boy, nobody love's me",
           "lyrics2":"He's just a poor boy, from a poor family",
           "lyrics3":"Spare him his life from this monstrosity!"}
for key, value in my_song.items():
    print(value)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14185898793139953, 'fraction_numerical': 0.011645140800338767, 'mean_word_length': 2.7018025078369905, 'pattern_counts': {'":': 7, '<': 26, '<?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': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '543980', 'license': 'MIT', 'n_tokens_mistral': 3246, 'n_tokens_neox': 3093, 'n_words': 1274, 'path': '3_Intro_Python&Jupyter.ipynb', 'repo_name': 'djproc/Data-Analysis-in-Python-for-Bench-Scientists', 'size': '9446'}