<jupyter_start><jupyter_text>Python BasicsBefore you get started on anything else, you'll need to understand Python, the programming language used throughout this tutorial. Let's go through some of the basics of Python together.  Strings & Print()A **String** is a simple data type that can include letters, numbers, and symbols. Simply speaking, it's a sequence of characters. Strings must be surrounded by a pair of quotation marks. Here's a couple examples:   * "This is a string!"  * "1234 & 5678" * "P Sherman 42 Wallaby Way Sydney" We use the **print()** function to display outputs in the console. In this case, the output will show up right below the coding cell.Now, it's your turn. Using the print() function provided below, enter a String inside the parenthesis that says *Hello World!* Click "Run" to display the output.<jupyter_code>print("5755421")<jupyter_output>5755421<jupyter_text>CommentsBefore we continue further, I want to show you how to comment the code you're working with. Commenting your code makes it easier to understand, both for yourself in the future and for other people. Comments are parts of the code that Python will not try to run. There's two different types of comments: Single-line, and multi-line. **Single-Line** comments are comments that only take up one line in your code. These kinds of comments are good if you need to include very brief information, such as quick notes for what a part of your code does. Single line comments are denoted with a a hashtag (  ). **Multi-line** comments, on the other hand, can be more thorough and are used for comments that take up multiple lines of code. Muti-line comments can also be used to "comment-out" parts of your code, if you do not want it to run. These kinds of comments are denoted by three pairs of quotation marks ( """ ) on either side of the comment. Here's a couple examples of each: * This is a single line comment * """This is a multi line comment.         Anything I say and/or any code I write will not be run by Python     End comment."""Now you try. First, run the code below to see the output. Then, add a single-line above the first print() function in the cell below. Then, comment-out the second and third print() funtions using a multi-line comment. Now run it again.<jupyter_code>print("Add your single line comment above this function")

print("Comment this function out.")
print("And this one too!")


#You see how the last two Strings do not show up when you run the code the second time?<jupyter_output>Add your single line comment above this function
Comment this function out.
And this one too!<jupyter_text>Variables and AssignmentOne way to store and work with different types of data is by using **variables**. Variables stores data under the name you decide to give it. You can **assign** the variable different pieces of data by using the equals ( = ) symbol. For example, if I wrote myFirstVariable = 24mySecondVariable = "Hello!"(***Please do note that the "=" sign is for assignment, not for comparison. The symbol for comparison is a double-equals sign ( == ).***)In the above examples, I assigned myFirstVariable to hold the number 24. I assigned mySecondVariable to hold the String "Hello!"In each case, the name (myFirstVariable/mySecondVariable) is the name of the variable, but it holds different types of data. One holds a number, and one holds a String. Create two different variables in the cell below and assign them any number or String value you want. Then, print both variables out using two print() functions. Be sure to put the name of your variables inside the print function in order to see it printed out on the screen.<jupyter_code># This is example code below. 

var1 = "last"
var2 = 64

print(var1)
print(var2)

#Notice that only the data each variable holds is printed out! Not the variable name itself!<jupyter_output>last
64<jupyter_text>OperationsPython allows you to perform different mathematical operations in your code, including but not limited to:* Addition (using the + sign) * Subtraction ( - )* Multiplication ( * ) * Division ( / ) * Exponents ( double asterisks with no space in between: **  ... Ex:  2 (double asterisks) 3  is 2 raised to the power of 3.)* Modulus ( % ...this finds the remainder after you divide two numbers) Here's a quick example:  * ten = 5 * 2In the above example, "ten" is the *name* of the variable. The variable is then assigned the product of 5 and 2 (10).Practice using the operations named above. Do the following: Declare a variable named "first" and assign it two numbers that are added together to equal 15.  Declare a second variable that is assigned the value 14.Print out both variables using print(). Create a third variable called "mod" and assign it to be your first variable modulo your second variable. Print out your third variable. It should print out a 1.<jupyter_code># Insert your code here<jupyter_output><empty_output><jupyter_text>Conditional Statements and Booleans A **boolean** can only have the values "True" or "False", either implied or explicitly stated. For example, study the following lines:myBoolean = TruemySecondBoolean = False myBoolean == mySecondBooleanIn the first line of code above, I assigned myBoolean the value "True" (Capitalization matters!). I then assigned mySecondBoolean the value "False". If I printed these variables out, they'd print out "True" and "False" respectively. This explicitly named either variable as either True or False. Now, in the third line, I used the double-equals (==) operator to check if myBoolean equals mySecondBoolean. But True does NOT equal False, therefore if I printed the third line out, it would read False. In the third line of code, the True/False statement is implicit. In the code cell provided below, declare your own variables and copy what I've done above to see the code run for yourself. Then, try changing the True/False values and see what difference it makes.<jupyter_code># Insert code here.<jupyter_output><empty_output><jupyter_text>Now let's look at conditional statements. In regular plain English, conditional statements are written in an "if...then...else" format. *If* the condition is met, *then* the second half of the sentence is valid. *Else* the other statement is valid. ("If it snows heavily, then they may cancel school! Or else we'll have to attend school this Monday.) Conditional statements in programming work the same way. If the condition is met, then the code below it will be executed. If it is not met, then nothing happens and that piece of code is ignored. In Python, the format for writing conditional statements looks like this: if [statement here]:    CODETOEXECUTE_Aelif [statement]:     CODETOEXECUTE_Belse:     CODETOEXECUTE_C   **Be mindful of the indentations! They DO matter. Any code that is indented will only be executed if the if statement above it is met. **    If you only want one conditional statement, you can use just the first block of code ( if ([statement here]):    CODETOEXECUTE_A ). If there are two conditional statements, use the first and last block of code ( if ([statement here]):    CODETOEXECUTE_A   and else: CODETOEXECUTE_C ).         Look at the code provided below. Run it and look at the result. Which conditional statement was met?Then, manipulate the code to make each if-statement true in turn. (This means you'll hit "RUN" three times. Once after every edit.)<jupyter_code>x = 4 


if x == 2: 
    print("x equals 2!")
elif x == 45: 
    print("x equals 45!")
else: 
    print("x equals 46")<jupyter_output>x equals 46<jupyter_text>Python ListsInside Python, there's a data structure called a List. Lists hold any number of any kind of variable. Here's how to declare a list in Python. myFirstList = []Then, you can add variables to that list by using the append() function. For example: myFirstList.append(1) myFirstList.append(2)myFirstList.append(3)This adds the numbers 1, 2, and 3 to your List. In order to go through your lists, you can use the following format to print out individual variables. print(myFirstList[0])print(myFirstList[1])print(myFirstList[2])**NOTE: Lists begin with 0 as the first index. So our "1" is stored at index 0, "2" is stored at index 1, and so on.** If you're trying to print the whole list, you can just print it like this: print(myFirstList) This will print out all your variables that you've stored, in order. Now you try: The code below is incorrect and incomplete. Add the necessary pieces of code to make this code run correctly and print out the list.<jupyter_code>#This code is incorrect. Fix the mistakes.

myList = ()

myList.append("String 1")
myList.append("String 2")

print(myList[2])



#The code should print out "String 2" followed by ['String 1', 'String 2'] on the next line.<jupyter_output><empty_output><jupyter_text>DictionariesA Dictionary is similar to a List, but works with two values (a key and a value) instead of using an index. A Dictionary can be declared like this: favoriteColors = {       "Jane" : "purple",       "John" : "blue",       "Mary" : "pink"              }       Copy/paste the code above and print out the result using print(favoriteColors).<jupyter_code># This is the code they'd have.


favoriteColors = {
       "Jane" : "purple",
       "John" : "blue",
       "Mary" : "pink"
       
       }

print(favoriteColors)<jupyter_output><empty_output><jupyter_text>You can remove values from your Dictionary by using the .pop() method. Example: favoriteColors.pop("Jane") This would remove Jane from your Dictionary. Try this in the cell above, where you've pasted the Dictionary I gave you. Use the .pop() method under the print() method. Then print the newly edited dictionary using a second print() function. Now it's your turn! Create your own Dictionary and practice adding and deleting key/value pairs. Print the result each time, to see how this has changed your Dictionary.<jupyter_code># Insert your code here<jupyter_output><empty_output><jupyter_text>Loops   Loops are useful for when we need to repeat a block of code over and over again. There are two types of loops you'll see in Python, **for loops** and **while loops**.       A **for loop** goes over a sequence a certain number of times. To show you how this works, let's declare a list of fruits, and then use a for loop to print out each fruit in the list.<jupyter_code>#Declare a list of 5 fruits
Fruits = ["Apple", "Banana", "Plum", "Cherry", "Pear", "Orange"]

#For loop used to print out each name."For every fruit (element) in the "Fruits" list, print out the fruit.
for fruits in Fruits:
 print(fruits);<jupyter_output><empty_output><jupyter_text>The second type of loop is a **while loop**. A **while loop** is basically saying "while _ABC_-condition is true, do _XYZ_". Let's use our previous example of a Fruits list to show a while loop. We'll declare a list of Fruits, and then use a while loop to print out the names, as long as a certain condition is met. Let's say our condition is that the variable "i" cannot be larger than the length of the list. Study the code below.<jupyter_code>#Declare our list of Fruits once again
Fruits = ["Apple", "Banana", "Plum", "Cherry", "Pear", "Orange"]

#Declare our variable, "i"
i = 0

#Now, while count < list length, we'll print out the fruits
while count < len(Fruits):
    print(Fruits[i])
    i = i + 1
#This adds +1 digit to "i". This way, "i" increases by +1 every time we print a fruit.<jupyter_output><empty_output><jupyter_text>Functions One of the last things I'll introduce you to are called **functions**. A function is a piece of reusable code that performs a single action. These can be helpful if you need to do a certain procedure over and over again. It also makes your code more readable. To define a function, you use the keyword "def" before a space, and then the function name. For example:* def printHelloWorld():      print("Hello World!") This function would print "Hello World!" to the console (or in our case, right under this cell block). To _use_ the function you created, you need to "call" it. Calling a function is basically referring to to it from a different part of the code. To call a function you just type the name followed by parentheses "()". Any arguements needed for the function go inside the parenthesis. To better understand this, study the code below.<jupyter_code># This is a function, that's going to print hello World. 
def printHelloWorld():
    print("Hello World!")
    
# Run the cell. Nothing appears in the console right now, right? 
# In order to actually use the function, we're going to call it. Uncomment the line below 
# (meaning, delete the # before the print function and run this cell block to see 'Hello World!' appear. 

# printHelloWorld()<jupyter_output><empty_output><jupyter_text>A function can have multiple arguements. The one we just did had no arguments, so nothing went inside the parentheses when we called it. So suppose we want to add two numbers inside a function. Here's what it would look like. * def addTwoNum(x, y):      return x + y      Then, when we call it, we'd need to have two numbers separated by commas inside our parentheses. So it looks like this.* addTwoNum(1, 2)This function, when called, adds the numbers one plus two and returns the sum. Let's do one quick exercise.<jupyter_code># Create a function that multiplies three numbers (1, 2, 4) and returns the product (8).<jupyter_output><empty_output><jupyter_text>Optional Arguments In FunctionsIn Python, functions can have default values. If the coder doesn't put in a value for that function, it will default to a predefined value. Let's look at an example to clarify this. * def findTrianglePerimeter( side1, side2 = 5, side3 = 5):    return print(side1 + side2 + side3) When we call this function, we have choose to omit the arguements for side2 and side3. If we don't specifiy them, they will default to "5". Let's look at the code below. * findTrianglePerimeter(2);   <-- This function will use "5" as the default values for side2 and side3. 2 (our value for side1) + 5 + 5 = 12. This function should print out 12 to the console. * findTrianglePerimeter(2, 4);   <-- This will use "4" as our value for side2, and use our default "5" as the value for side3. 2 + 4 + 5 = 11. This function should print out 11 to the console. * findTrianglePerimeter(2, 4, 6); <-- This uses "4" as side2, and "6" for side3. 2 + 4 + 6 = 12, so it should print 12 to the console. * findTrianglePerimeter(1, side3 = 4); <-- In this case, we'll set side3 to be "4", but don't give a value for side2. Therefore, side2 defaults to "5". 1 + 5 + 4 = 10. This should print 10 to the console.This function is also put in the cell below. Try changing values inside the parenthesis and see how it changes the result!<jupyter_code>def findTrianglePerimeter(side1, side2 = 5, side3 = 5):
    return print(side1 + side2 + side3)

# Change the numbers inside the parenthesis to see what happens when you run this cell.  
findTrianglePerimeter(1); 


#You may also want to comment out the above function and create your own function below.<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07253269916765755, 'fraction_numerical': 0.011031840401638262, 'mean_word_length': 4.325008793527964, 'pattern_counts': {'":': 0, '<': 59, '<?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': '14', 'dir': 'jupyter-structured-clean-dedup', 'id': '574040', 'license': 'Beerware', 'n_tokens_mistral': 4172, 'n_tokens_neox': 3959, 'n_words': 2291, 'path': 'Section_02/Python_Basics.ipynb', 'repo_name': 'soft-eng-practicum/MLStocks', 'size': '15138'}