├── LICENSE ├── code-examples ├── 01-data-types-variables.py ├── 02-combine-compare.py ├── 03-if-elif-else.py ├── 04-lists-loops.py ├── 05-dictionaries.py └── 06-functions.py ├── exercises ├── reading-exercises │ ├── 1.py │ ├── 2.py │ ├── 3.py │ ├── 4.py │ ├── 5.py │ └── readme.md └── writing-exercises │ ├── 01-is-palindrome.py │ ├── 02-is-anagram.py │ ├── 03-find-duplicates.py │ ├── 04-min-and-max-occurence.py │ ├── 05-bonus-rock-paper-scissors.py │ ├── readme.md │ └── solutions │ ├── 01-is-palindrome.py │ ├── 02-is-anagram.py │ ├── 03-find-duplicates.py │ ├── 04-min-and-max-occurence.py │ └── 05-bonus-rock-paper-scissors.py ├── lesson-plan.md └── readme.md /LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /code-examples/01-data-types-variables.py: -------------------------------------------------------------------------------- 1 | # We can create variables by giving them a name, and 2 | # using the assignment operator, the equals sign (=) 3 | # to give them a value. 4 | 5 | # Data comes in a variety of types. These two versions 6 | # of the number one are not the same. One is a number, 7 | # the other is a piece of text. 8 | x = 1 9 | y = '1' 10 | 11 | # We can print the "type" of our two variables like this: 12 | print('\n===quotes===') 13 | print(type(x)) 14 | print(type(y)) 15 | 16 | # There are three kinds of numbers in python: integers, floats, and complex numbers 17 | integer_example = 2 18 | float_example = 0.1 19 | complex_example = 4+3j # These are rarely important for most programmers... 20 | 21 | print('\n===number types===') 22 | print(type(integer_example)) 23 | print(type(float_example)) 24 | print(type(complex_example)) 25 | 26 | # Booleans are either True or False 27 | t = True 28 | f = False 29 | 30 | print('\n===booleans===') 31 | print(type(t)) 32 | print(type(f)) 33 | 34 | # There is a special value that means "nothing" 35 | nothing = None 36 | 37 | print('\n===None===') 38 | print(type(nothing)) 39 | 40 | # And textual data, called strings, are wrapped in quotes 41 | text = "This is a string." 42 | print(type(text)) 43 | 44 | # Micro-Exercise: Create a variable and assign it a value. 45 | # Then, pick one of the variables defined above and reassign 46 | # it to have the same value as the variable you created. 47 | # Finally, prove your code works with a print statement. 48 | -------------------------------------------------------------------------------- /code-examples/02-combine-compare.py: -------------------------------------------------------------------------------- 1 | # Numbers can be combined using mathematical operators 2 | x = 1 + 1 3 | y = 2 * 3 4 | 5 | # Variables holding numbers can be used any way numbers can be used 6 | z = y / x 7 | 8 | # We can prove that these computations worked out the same 9 | # using comparison operators, specifically == to test for equality: 10 | print('===comparing===') 11 | print('2 == x', 2 == x) 12 | print('6 == y', 6 == y) 13 | print('3 == z', 3 == z) 14 | 15 | print() # Just for a blank line in the output 16 | 17 | # Two values can only be equal if they have the same type 18 | print("1 == '1'", 1 == '1') 19 | 20 | # Other common comparisons include <, <=, >, >= 21 | print('1 < 2', 1 < 2) # True 22 | print('10 >= 10', 10 >= 10) # True 23 | print('10 > 10', 10 > 10) # False 24 | 25 | print() # For a blank line in the output 26 | 27 | # Strings are compared pseudoalphabetically for greater than / less than 28 | print('"albert" < "bill"', "albert" < "bill") # True 29 | 30 | # HOWEVER, in python ALL capital letters come before ANY lowercase letters 31 | print('"B" < "a"', "B" < "a") # True 32 | 33 | # There are additional rules for other characters like $, %, ., and so on 34 | # that we're ignoring for now. 35 | 36 | # Strings can also be combined with math operators, but they mean different 37 | # things when operating on strings 38 | x = "hello " + "world." # Concatination, x is "hello world." 39 | y = "a" * 4 # Duplication, y = "aaaa" 40 | 41 | print() 42 | print(x) 43 | print(y) 44 | 45 | # Finally, we can combine the assignment operator and these math operations 46 | # using the following shorthands: 47 | x = 4 48 | x + 3 # x = x + 3 49 | x -= 1 # x = x - 1 50 | x *= 2 # x = x * 2 51 | x /= 4 # x = x / 4 52 | 53 | # Micro-Exercise: predict the value of x. Then write a comparison statement 54 | # involving x that evaluates to False. Print the result of that comparison. 55 | -------------------------------------------------------------------------------- /code-examples/03-if-elif-else.py: -------------------------------------------------------------------------------- 1 | # We use if, if/else, and if/elif/else blocks to selectively 2 | # execute code when something is true. 3 | 4 | if True: 5 | print("This executes") 6 | print("this also executes") 7 | 8 | 9 | 10 | if False: 11 | print("This never executes") 12 | print("this also never executes") 13 | 14 | 15 | # The above are trivial, but using comparison operators makes 16 | # these constructs very useful: 17 | 18 | arbitrary_number = 42 19 | 20 | # Only ONE of an if/else block can trigger. 21 | if arbitrary_number > 10: 22 | print("The number is larger than 10") 23 | else: 24 | print("The number is not larger than 10") 25 | 26 | # Same for an if/elif/else, exactly one block can trigger. 27 | # But you can have any number of elifs 28 | if arbitrary_number < 10: 29 | print("The number is less than 10") 30 | elif arbitrary_number < 20: 31 | print("The number is between 10 and 20") 32 | elif arbitrary_number < 30: 33 | print("The number is between 20 and 30") 34 | else: 35 | print("The number is 30 or larger") 36 | 37 | # comparisions can be combined using and / or 38 | # they can also be negated with not 39 | if not arbitrary_number > 10: 40 | print("The number is NOT greater than 10.") 41 | 42 | if arbitrary_number > 10 and arbitrary_number < 50: 43 | print("The number is greater than 10 AND less than 50") 44 | 45 | if arbitrary_number < 10 or arbitrary_number > 30: 46 | print("The number is less than 10, or more than 30") 47 | 48 | # Micro-Exercise: Create a variable, assign it a numerical value 49 | # then write an if/else statement that will cause the variable 50 | # to become half as large if it's greater than 100, and twice 51 | # as large if it's less than 100. Print the variable's value 52 | # after the if/else block and test that your code works. -------------------------------------------------------------------------------- /code-examples/04-lists-loops.py: -------------------------------------------------------------------------------- 1 | # We often have values that should be grouped. 2 | # Python offers two main "collections" for such cases: 3 | # the list and the dictionary. 4 | 5 | # Lists are an ordered collection of items. 6 | # We can make a new one using square brackets: [] 7 | empty_list = [] 8 | l_one = [1, 2, 3, 4, 5, 6] 9 | l_two = ['a', 'b', 'c', 'd', 'e', 'f'] 10 | 11 | # We choose the order, so this is perfectly allowed: 12 | l_three = [6, 1, 2 , 5, 4, 3] 13 | 14 | # We can fetch a particular item from the list using "bracket notation" 15 | # Programmers pronounce this line of code "print l_one sub zero" and it 16 | # returns the item in the first position of the list, which is the number 1. 17 | print(l_one[0]) 18 | 19 | # So what does this print? 20 | print(l_two[3]) 21 | 22 | # What about this? 23 | print(l_three[-1]) 24 | 25 | # Bracket notation can also be used to modify values in the list 26 | l_one[0] = 999 27 | print(l_one) 28 | 29 | # What about this? (Hint: it's commented out for a reason...) 30 | # print(l_three[6]) 31 | 32 | # looping over lists is easy in Python with the "for loop" 33 | print("\nFor l_one: ") 34 | for i in l_one: 35 | print(i) 36 | 37 | print("\nFor l_two: ") 38 | for i in l_two: 39 | print(i) 40 | 41 | print("\nFor l_three: ") 42 | for i in l_three: 43 | print(i) 44 | 45 | # Sometimes it is useful to have the index value 46 | # as well as the value from the list. In Python we 47 | # can use the enumerate function for this: 48 | print("\nenumerate") 49 | for index, value in enumerate(l_two): 50 | print(index, value, l_two[index-1]) 51 | 52 | # Lists have many useful functions built in that we can use, such as 53 | # append for adding an item to the end of a list, and the len function 54 | # for determining how many items are in a list. See the docs for more: 55 | # https://docs.python.org/3/tutorial/datastructures.html 56 | 57 | new_list = [] 58 | new_list.append('hello') 59 | new_list.append('good') 60 | new_list.append('people') 61 | 62 | print("\n", new_list, len(new_list)) 63 | 64 | # Micro-Exercise: append three more values to new_list, then loop 65 | # over those values printing the value AND type of each item in new_list. 66 | -------------------------------------------------------------------------------- /code-examples/05-dictionaries.py: -------------------------------------------------------------------------------- 1 | # Dictionaries are the second main built in way to handle 2 | # collections of data. Instead of an ordered collection 3 | # like the list, dictionaries are unordered key/value pairs. 4 | 5 | # To make a dictionary we use curly braces: {} 6 | empty_dictionary = {} 7 | 8 | # Many types of data can be keys, and ANY type of data can be a value 9 | key_examples = { 10 | "tyler": 75, 11 | 1: "24", 12 | y None: [1, 2, 3, 'Ghastly Business'] 13 | } 14 | 15 | # We can also add new key/value pairs using bracket notation: 16 | key_examples['new_key'] = 'new value' 17 | 18 | # We can fetch an item from a dictionary using bracket notation 19 | # similar to lists. 20 | print(key_examples['tyler']) # 75 21 | 22 | # We can also use a built in function called get, which 23 | # returns None if no element in the dictionary matches. 24 | print(key_examples.get('tyler')) 25 | 26 | # If we try to access a non-existant key with bracket notation 27 | # we get an error, which is a good reason to use .get 28 | 29 | # key_examples[7] # error, terminates program 30 | print(key_examples.get(7)) # prints None 31 | 32 | # We can also loop through dictionaries, but the order is decided 33 | # arbitrarily so remember not to rely on an order when doing so. 34 | 35 | print('\n===looping===') 36 | for key, value in key_examples.items(): 37 | print(key, value) 38 | 39 | # Micro-Exercise: nested inside of key_examples is the value 40 | # "Ghastly Business". Write a line of code that accesses that value, 41 | # stores it into a variable, and then prints the value of that variable 42 | # to a string. You should use "bracket notation" or the .get function 43 | -------------------------------------------------------------------------------- /code-examples/06-functions.py: -------------------------------------------------------------------------------- 1 | # Functions are blocks of code that we can reuse. 2 | # We define them using the keyword "def". 3 | # All functions need a name, and optionally may accept parameters. 4 | 5 | # This is a function without parameters. 6 | def compute_two(): 7 | return 1 + 1 8 | 9 | # This function has paremters. 10 | def add(parameter_one, parameter_two): 11 | return parameter_one + parameter_two 12 | 13 | # All functions return a value, and if a value is not explicitly 14 | # returned using the return keyword, then None is returned. 15 | 16 | def returns_none_and_does_nothing(): 17 | pass 18 | 19 | # We call, or envoke, functions with a similar syntax: 20 | x = compute_two() 21 | y = add(2, 3) 22 | z = returns_none_and_does_nothing() 23 | 24 | print(x, y, z) 25 | 26 | # We can also pass variables as parameters: 27 | q = add(x, y) 28 | print(q) 29 | 30 | # Micro-Exercise: create a function called fancy_math that 31 | # accepts 3 parameters, uses math operators to combine them 32 | # and returns the result of that math. The result should also 33 | # be a number. -------------------------------------------------------------------------------- /exercises/reading-exercises/1.py: -------------------------------------------------------------------------------- 1 | # What does this function do? 2 | def mystery_function(things, specific_thing): 3 | for thing in things: 4 | if specific_thing == thing: 5 | return True 6 | 7 | return False 8 | 9 | # What will this print when executed? 10 | return_value = mystery_function([1,2,3,4,5], 4) 11 | print(return_value) 12 | 13 | # What about this? 14 | return_value = mystery_function([1,2,3,4,5], '4') 15 | print(return_value) 16 | 17 | # Run this code to check your answers. -------------------------------------------------------------------------------- /exercises/reading-exercises/2.py: -------------------------------------------------------------------------------- 1 | # What does this function do? 2 | def mystery_function(names): 3 | counter = 0 4 | 5 | for name in names: 6 | if name[0] == 'A': 7 | counter += 1 8 | elif name[-1] == 'z': 9 | counter += 1 10 | 11 | return counter 12 | 13 | 14 | # How is this function different from the one above it? 15 | def mystery_function_two(names): 16 | counter = 0 17 | 18 | for name in names: 19 | if name[0] == 'A': 20 | counter += 1 21 | if name[-1] == 'z': 22 | counter += 1 23 | 24 | return counter 25 | 26 | 27 | # Test your understanding of the above functions by predicting their output 28 | # with the following input. 29 | student_names = [ 30 | 'Tyler', 31 | 'Taz', 32 | 'Amanda', 33 | 'Zeke', 34 | 'Adnan', 35 | 'Amoz', 36 | 'Frank' 37 | ] 38 | 39 | return_one = mystery_function(student_names) 40 | return_two = mystery_function_two(student_names) 41 | 42 | # What will these prints 43 | print(return_one) 44 | print(return_two) -------------------------------------------------------------------------------- /exercises/reading-exercises/3.py: -------------------------------------------------------------------------------- 1 | # What does this function do? 2 | # How should we intepret its output (the variable return_value) 3 | def mystery_function(input_string): 4 | return_value = {} 5 | 6 | for c in input_string: 7 | if return_value.get(c) == None: 8 | return_value[c] = 0 9 | 10 | return_value[c] += 1 11 | 12 | return return_value 13 | 14 | 15 | # What will the following code result in? 16 | # What does it mean? 17 | some_string = 'This is a boring sentence.' 18 | mystery_value = mystery_function(some_string) 19 | 20 | print(mystery_value) -------------------------------------------------------------------------------- /exercises/reading-exercises/4.py: -------------------------------------------------------------------------------- 1 | # This function doesn't return anything, but it does print a 2 | # lot of stuff. Before you run this function, predict what it 3 | # will print. 4 | 5 | def loops_in_loops(): 6 | c = 0 7 | 8 | for i in range(10): 9 | for j in range(10): 10 | print(i, j, c) 11 | c += 1 12 | 13 | 14 | loops_in_loops() 15 | 16 | # If this result confuses you, simulate its execution by 17 | # manually keeping track of the values in the variables 18 | # i, j and c as you step through the code line by line. -------------------------------------------------------------------------------- /exercises/reading-exercises/5.py: -------------------------------------------------------------------------------- 1 | # This code has better names, but does something we haven't seen before: 2 | # It calls a function from within another function. 3 | 4 | # Can you describe how these functions work together, and what the ultimate 5 | # result of this code is? 6 | 7 | def contains(items, item): 8 | for i in items: 9 | if item == i: 10 | return True 11 | 12 | return False 13 | 14 | 15 | def intersection(list_a, list_b): 16 | return_value = [] 17 | 18 | for item_a in list_a: 19 | if contains(list_b, item_a) and not contains(return_value, item_a): 20 | return_value.append(item_a) 21 | 22 | return return_value 23 | 24 | 25 | # Setup two lists... 26 | x = [1, 3, 5, 6, 7, 9, 1] 27 | y = [3, 4, 5, 8, 10, 1] 28 | 29 | # What will the following code print? 30 | print(intersection(x, y)) -------------------------------------------------------------------------------- /exercises/reading-exercises/readme.md: -------------------------------------------------------------------------------- 1 | # Code Reading Exercises 2 | 3 | Reading code is just as important (if not more important) than writing code. It's also easier to write code after working through a few examples of existing code. Open each of the Python files in this directory and answer the questions in the comments. Throughout the exercise, feel free to ask other students or the instructor for help! 4 | 5 | For each file, follow these steps: 6 | 7 | 1. Read the code (do not execute the code yet!). 8 | 2. Try to describe what the function or functions do. 9 | 3. Try to describe how the function(s) acheive that behavior. 10 | 4. Predict the output (each example prints some stuff). 11 | 5. Run the code and check your predictions. 12 | 6. If you were wrong, try to figure out why. 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /exercises/writing-exercises/01-is-palindrome.py: -------------------------------------------------------------------------------- 1 | """ 2 | Complete this function such that it returns True if and only if 3 | the string passed into this function is a palindrome, that is if 4 | it is the same string of characters forwards and in reverse. 5 | Return False otherwise. 6 | """ 7 | def is_palindrome(input_string): 8 | # Delete pass, and put your code here. 9 | pass 10 | 11 | 12 | # Very Simple Tests: 13 | assert is_palindrome('racecar') == True 14 | assert is_palindrome('battle') == False 15 | assert is_palindrome('wasitabatisaw') == True 16 | assert is_palindrome('a') == True 17 | assert is_palindrome('abca') == False 18 | ## ADD AT LEAST 3 MORE TESTS ## 19 | 20 | ## Just helpful to see, if this prints your tests all passed! 21 | print("All tests passed.") -------------------------------------------------------------------------------- /exercises/writing-exercises/02-is-anagram.py: -------------------------------------------------------------------------------- 1 | """ 2 | Complete this function such that it returns True if and only if 3 | the two strings passed to the function are anagrams of each other, 4 | that is if they contain the same letters the same number of times. 5 | Return False otherwise. 6 | """ 7 | def is_anagram(string_a, string_b): 8 | # Delete pass, and put your code here. 9 | pass 10 | 11 | 12 | # Very Simple Tests 13 | assert is_anagram('abba', 'aabb') == True 14 | assert is_anagram('aab', 'bba') == False 15 | assert is_anagram('the detectives', 'detect thieves') == True 16 | assert is_anagram('abcde', 'abcdf') == False 17 | ## ADD AT LEAST 3 MORE TESTS ## -------------------------------------------------------------------------------- /exercises/writing-exercises/03-find-duplicates.py: -------------------------------------------------------------------------------- 1 | """ 2 | Complete this function such that it returns a new list 3 | which contains all values that appear more than once in 4 | the list passed into the function. Each duplicated value 5 | should appear exactly once in the output list regardless 6 | of how many times it is duplicated. 7 | 8 | If no items are duplicated, return an empty list. 9 | """ 10 | def duplicates(input_list): 11 | # Delete pass, and put your code here. 12 | pass 13 | 14 | 15 | # Very Simple Tests 16 | # in Python == for two lists means "do the items in the list match exactly, order included" 17 | assert duplicates([1, 2, 3, 1]) == [1] 18 | assert duplicates([3, 3, 3, 3, 3]) == [3] 19 | 20 | # Note the use of sorted here: your function can return the duplicates 21 | # in any order, but calling sorted on them makes it easier to test the 22 | # output. 23 | assert sorted(duplicates([1, 2, 3, 4, 1, 2, 3, 4])) == [1,2,3,4] 24 | assert sorted(duplicates([1, 1, 2, 3, 3, 4])) == [1, 3] 25 | 26 | ## ADD AT LEAST 3 MORE TESTS ## -------------------------------------------------------------------------------- /exercises/writing-exercises/04-min-and-max-occurence.py: -------------------------------------------------------------------------------- 1 | """ 2 | Complete this function such that it returns a list with 3 | exactly two items. The first item should be the item that 4 | appears the MOST number of times in the provided input. 5 | The second item should be the item that occurs the fewest 6 | number of times in the provided input. 7 | 8 | The returned list can contain two of the same value, for example 9 | if the input list has exactly one element, this would be the case. 10 | 11 | If there are ties, e.g. input_list == [1, 1, 2, 2] your function 12 | can select arbitrarily, that is the following would ALL be correct: 13 | [1, 1], [1, 2], [2, 1], [2, 2] 14 | 15 | If the input list is empty, return an empty list. 16 | """ 17 | def most_and_least_common(input_list): 18 | # Delete pass, and put your code here. 19 | pass 20 | 21 | 22 | # Very Simple Tests 23 | assert most_and_least_common([]) == [] 24 | assert most_and_least_common([1]) == [1, 1] 25 | assert most_and_least_common([1,2,2]) == [2, 1] 26 | assert most_and_least_common([1, 2, 1, 2, 3, 1, 2, 2]) == [2, 3] 27 | 28 | ## ADD AT LEAST 3 MORE TESTS ## 29 | ## How will you test for ties...? 30 | 31 | 32 | ## Just helpful to see, if this prints your tests all passed! 33 | print("All tests passed.") -------------------------------------------------------------------------------- /exercises/writing-exercises/05-bonus-rock-paper-scissors.py: -------------------------------------------------------------------------------- 1 | # Write a script that, when executed, allows the user to 2 | # play a game of rock paper scissors against a computer. 3 | # To do this, you will need to accept input from the user, 4 | # and use python's random module to control the computer's 5 | # choices... 6 | 7 | # Here is a little code to help you get started: 8 | 9 | # This builtin function, choice, randomly selects an item from a list. 10 | from random import choice 11 | sample_list = ['a', 'b', 'c', 'd'] 12 | 13 | 14 | 15 | player_typed = input("Type something...\n> ") 16 | print("Random selection: ", choice(sample_list)) 17 | print("Player typed: ", player_typed) 18 | -------------------------------------------------------------------------------- /exercises/writing-exercises/readme.md: -------------------------------------------------------------------------------- 1 | # Solving Problems With Python 2 | 3 | In all of the following exercises you'll be asked to complete a function that performs some task using Python. A couple simple tests are provided for each exercise but these tests are **not** exhaustive, and you'll be asked to expand the tests each time. Throughout the exercise, feel free to ask other students or the instructor for help! 4 | 5 | For each of the exercises, follow these steps: 6 | 7 | 1. Read the problem description carefully. 8 | 2. Look at the provided tests, do they match your understanding of the problem? 9 | 3. Write at least 3 more tests. 10 | 4. Complete the function so that it correctly solves the problem 11 | * You will want to run the code **a lot** during this part. 12 | 5. When your code passes all the tests, ask yourself: "Can I break this?" 13 | * Add 2 more tests with the goal of finding a test that breaks your code. 14 | * If you succeed at breaking your code, fix the bug you just found! 15 | 6. In a professional setting, you'd likely repeat step 5 several more times. 16 | * Feel free to repeat step 5 if you can think of more edge cases that might break your function. 17 | * But don't get stuck on this step for too long. -------------------------------------------------------------------------------- /exercises/writing-exercises/solutions/01-is-palindrome.py: -------------------------------------------------------------------------------- 1 | """ 2 | Complete this function such that it returns True if and only if 3 | the string passed into this function is a palindrome, that is if 4 | it is the same string of characters forwards and in reverse. 5 | Return False otherwise. 6 | 7 | This solution computes the midpoint of the input_string and then 8 | compares letters from the outside in, one by one, until it gets 9 | to the two center. 10 | 11 | len(input_string) // 2 --> divides by two, then rounds down. 12 | range(any_number) --> returns an iterator with integers from 0 to (any_number - 1) 13 | """ 14 | def is_palindrome(input_string): 15 | front = 0 16 | back = -1 17 | for _ in range(len(input_string) // 2): 18 | if input_string[front] != input_string[back]: 19 | return False 20 | 21 | front += 1 22 | back -= 1 23 | 24 | return True 25 | 26 | 27 | # Very Simple Tests: 28 | assert is_palindrome('racecar') == True 29 | assert is_palindrome('battle') == False 30 | assert is_palindrome('wasitabatisaw') == True 31 | assert is_palindrome('a') == True 32 | assert is_palindrome('abca') == False 33 | ## ADD AT LEAST 3 MORE TESTS ## 34 | assert is_palindrome('') == True 35 | assert is_palindrome('aa') == True 36 | assert is_palindrome('ab') == False 37 | assert is_palindrome('aba') == True 38 | assert is_palindrome('abb') == False 39 | 40 | 41 | ## Just helpful to see, if this prints your tests all passed! 42 | print("All tests passed.") -------------------------------------------------------------------------------- /exercises/writing-exercises/solutions/02-is-anagram.py: -------------------------------------------------------------------------------- 1 | """ 2 | Complete this function such that it returns True if and only if 3 | the two strings passed to the function are anagrams of each other, 4 | that is if they contain the same letters the same number of times. 5 | Return False otherwise. 6 | 7 | This solution loops through each string once and maintains a counter 8 | based on the characters it encounters. For the first string it increases 9 | the count assoicated with that letter by one. For the second string it 10 | decreases the count by one. 11 | 12 | If the counter object ends with counts of 0 for all characters, then 13 | the two strings must be anagrams. If any values are not 0 then the two 14 | strings cannot be anagrams. The final loop performs this check. 15 | """ 16 | def is_anagram(string_a, string_b): 17 | counter = {} 18 | 19 | for c in string_a: 20 | if counter.get(c) == None: 21 | counter[c] = 0 22 | 23 | counter[c] += 1 24 | 25 | for c in string_b: 26 | if counter.get(c) == None: 27 | counter[c] = 0 28 | 29 | counter[c] -= 1 30 | 31 | for c, count in counter.items(): 32 | if count != 0: 33 | return False 34 | 35 | return True 36 | 37 | 38 | # Very Simple Tests 39 | assert is_anagram('abba', 'aabb') == True 40 | assert is_anagram('aab', 'bba') == False 41 | assert is_anagram('the detectives', 'detect thieves') == True 42 | assert is_anagram('abcde', 'abcdf') == False 43 | ## ADD AT LEAST 3 MORE TESTS ## 44 | assert is_anagram('abcde', 'ebcda') == True 45 | assert is_anagram('AbA', 'aba') == False # Letters are case sensitive! 46 | assert is_anagram('aaaa', 'aaaa') == True 47 | assert is_anagram('aaaa', 'aaa') == False 48 | 49 | ## Just helpful to see, if this prints your tests all passed! 50 | print("All tests passed.") -------------------------------------------------------------------------------- /exercises/writing-exercises/solutions/03-find-duplicates.py: -------------------------------------------------------------------------------- 1 | """ 2 | Complete this function such that it returns a new list 3 | which contains all values that appear more than once in 4 | the list passed into the function. Each duplicated value 5 | should appear exactly once in the output list regardless 6 | of how many times it is duplicated. 7 | 8 | If no items are duplicated, return an empty list. 9 | 10 | This solution uses the "in" keyword, which returns true if 11 | the item is in the collection and also uses the "slice" syntax: 12 | 13 | thing in collection --> returns True if thing is in collection. 14 | input_list[i+1:] --> returns a list with all the elements from index 15 | i+1 to the end of that list. 16 | 17 | Using these two features the solution checks if the current item occurs 18 | in the list anywhere after the current item, then checks if that item 19 | is not already in the return list. If both are true, it adds the current 20 | item to the return list. 21 | """ 22 | def duplicates(input_list): 23 | return_list = [] 24 | for i, item in enumerate(input_list): 25 | if item in input_list[i+1:] and item not in return_list: 26 | return_list.append(item) 27 | 28 | return return_list 29 | 30 | 31 | # Very Simple Tests 32 | # in Python == for two lists means "do the items in the list match exactly, order included" 33 | assert duplicates([1, 2, 3, 1]) == [1] 34 | assert duplicates([3, 3, 3, 3, 3]) == [3] 35 | 36 | # Note the use of sorted here: your function can return the duplicates 37 | # in any order, but calling sorted on them makes it easier to test the 38 | # output. 39 | assert sorted(duplicates([1, 2, 3, 4, 1, 2, 3, 4])) == [1,2,3,4] 40 | assert sorted(duplicates([1, 1, 2, 3, 3, 4])) == [1, 3] 41 | 42 | ## ADD AT LEAST 3 MORE TESTS ## 43 | assert duplicates([1, 2, 3, 4, 5, 6]) == [] 44 | assert duplicates([1, 2, 3, 1, 5, 1]) == [1] 45 | assert duplicates([1, 2, 3, 4, 6, 6]) == [6] 46 | 47 | ## Just helpful to see, if this prints your tests all passed! 48 | print("All tests passed.") -------------------------------------------------------------------------------- /exercises/writing-exercises/solutions/04-min-and-max-occurence.py: -------------------------------------------------------------------------------- 1 | """ 2 | Complete this function such that it returns a list with 3 | exactly two items. The first item should be the item that 4 | appears the MOST number of times in the provided input. 5 | The second item should be the item that occurs the FEWEST 6 | number of times in the provided input. 7 | 8 | The returned list can contain two of the same value, for example 9 | if the input list has exactly one element, this would be the case. 10 | 11 | If there are ties, e.g. input_list == [1, 1, 2, 2] your function 12 | can select arbitrarily, that is the following would ALL be correct: 13 | [1, 1], [1, 2], [2, 1], [2, 2] 14 | 15 | If the input list is empty, return an empty list. 16 | """ 17 | def most_and_least_common(input_list): 18 | # To handle the requirement of returning an empty list 19 | # for an empty input list. 20 | if len(input_list) == 0: 21 | return [] 22 | 23 | counter = {} 24 | for item in input_list: 25 | if counter.get(item) == None: 26 | counter[item] = 0 27 | 28 | counter[item] += 1 29 | 30 | # These values are chosen to be impossible so that 31 | # the time through the following loop, the initial 32 | # comparisons will always be True 33 | min_count = len(input_list) + 1 34 | min_value = None 35 | 36 | max_count = 0 37 | max_value = None 38 | print(counter) 39 | for item, count in counter.items(): 40 | if count < min_count: 41 | min_count = count 42 | min_value = item 43 | 44 | if count > max_count: 45 | max_count = count 46 | max_value = item 47 | 48 | return [max_value, min_value] 49 | 50 | 51 | 52 | # Very Simple Tests 53 | assert most_and_least_common([]) == [] 54 | assert most_and_least_common([1]) == [1, 1] 55 | assert most_and_least_common([1,2,2]) == [2, 1] 56 | assert most_and_least_common([1,2,3,4,5,1,2,3,4,1,2,3,1,2,1]) == [1, 5] 57 | 58 | ## ADD AT LEAST 3 MORE TESTS ## 59 | print(most_and_least_common([1, 2, 1, 2, 3, 1, 2, 2])) 60 | assert most_and_least_common([1, 2, 1, 2, 3, 1, 2, 2]) == [2, 3] 61 | 62 | ## Unfortunately, it's not as easy to test for ties, but here is one way in 3 lines: 63 | computed_answer = most_and_least_common([1, 1, 2, 2]) 64 | assert computed_answer[0] in [1, 2] 65 | assert computed_answer[1] in [1 ,2] 66 | 67 | # Another test for ties, one most but a tie for least 68 | computed_answer = most_and_least_common([1, 1, 1, 2, 2, 3, 3, 4, 4]) 69 | assert computed_answer[0] == 1 70 | assert computed_answer[1] in [2 ,3, 4] 71 | 72 | 73 | ## Just helpful to see, if this prints your tests all passed! 74 | print("All tests passed.") -------------------------------------------------------------------------------- /exercises/writing-exercises/solutions/05-bonus-rock-paper-scissors.py: -------------------------------------------------------------------------------- 1 | # Write a script that, when executed, allows the user to 2 | # play a game of rock paper scissors against a computer. 3 | # To do this, you will need to accept input from the user, 4 | # and use python's random module to control the computer's 5 | # choices... 6 | 7 | # Here is a little code to help you get started: 8 | 9 | # This builtin function, choice, randomly selects an item from a list. 10 | from random import choice 11 | 12 | # For strings that you use repeatedly, it's a common best practice to 13 | # define them once, then use the variables. This reduces errors from typos 14 | # and makes things easier to change in the future (e.g. capitalizing Rock Paper Scissors...) 15 | rock = 'rock' 16 | paper = 'paper' 17 | scissors = 'scissors' 18 | choices = [rock, paper, scissors] 19 | 20 | player_choice = None 21 | while player_choice == None: 22 | player_choice = input("Do you throw rock, paper, or scissors?\n> ") 23 | if player_choice not in choices: 24 | print(f'Sorry, you must type rock, paper, or scissors EXACTLY. You typed: {player_choice}\n') 25 | player_choice = None 26 | 27 | computer_choice = choice(choices) 28 | 29 | # To save some typing, I stored all the messages in variables. 30 | loss = "You lost." 31 | win = "You win!" 32 | draw = "It's a tie..." 33 | error = "This message should not be displayed... is the game broken?" 34 | outcome_message = None 35 | 36 | # This nested if/else block is annoying to write... 37 | # but sometimes you just have to encode the rules. 38 | if player_choice == computer_choice: 39 | outcome_message = draw 40 | elif player_choice == rock: 41 | if computer_choice == paper: 42 | outcome_message = loss 43 | elif computer_choice == scissors: 44 | outcome_message = win 45 | else: 46 | outcome_message = error 47 | elif player_choice == paper: 48 | if computer_choice == rock: 49 | outcome_message = win 50 | elif computer_choice == scissors: 51 | outcome_message = loss 52 | else: 53 | outcome_message = error 54 | elif player_choice == scissors: 55 | if computer_choice == rock: 56 | outcome_message = loss 57 | elif computer_choice == paper: 58 | outcome_message = win 59 | else: 60 | outcome_message = error 61 | else: 62 | outcome_message == error 63 | 64 | # Okay great, now just print the messages! 65 | print(f'You chose: {player_choice}. Computer chose: {computer_choice}... {outcome_message}') 66 | -------------------------------------------------------------------------------- /lesson-plan.md: -------------------------------------------------------------------------------- 1 | # Coding Essentials Outline 2 | 3 | This class is a one-day workshop designed for students with little-to-no programming experience to gain familiarity programming concepts, software ecosystems, and ultimately learn to write a little bit of code themselves. However, the goals of this class are more about fostering empathy and understanding between less-technical people and engineers than they are about making the students into programmers. 4 | 5 | _Note to instuctors_: in this lesson plan anything in **bold** is meant to be a question posed to your students. Anything in _italics_ is either a further instruction to you or the answer to a **question**. Everything else is something you might say out loud to the class. 6 | 7 | **Remember: This is a one-day workshop, you can only do so much. Work the clock and use students' time efficently as much as possible.** 8 | 9 | ## Objectives 10 | 11 | * Students can describe the main components of modern software infrastructure, and how they are connected. Especially the following: 12 | * Point of Sale Systems 13 | * Databases & Data Warehouses 14 | * Web servers (their own and 3rd party APIs) 15 | * Browsers 16 | * Heavy Compute Machines (e.g. for data science workloads) 17 | * Cloud Compute Infrastructure generally. 18 | 19 | * Students can describe the main infrastructural components software development & deployment. Especially: 20 | * Developers’ Local environment vs staging vs production 21 | * Version control repositories 22 | * Deployment infrastructure (CI/CD such as Jenkins, AWS role, “dev ops”) 23 | * Monitoring infrastructure 24 | 25 | * **(Less Important, skippable):** Students can describe that different languages are used for different tasks, and a little bit about why. Especially: 26 | * Python (almost everything, “2nd best language for every task”) 27 | * JavaScript (Websites, but increasingly a little more) 28 | * Java / C# (Web infrastructure, games, enterprise) 29 | * C / C++ (Systems, low level) 30 | * SQL (totally different, just for getting data from a database!) 31 | 32 | * Students can identify and define fundamental building blocks of code 33 | * Print and the importance of the console 34 | * Data types & collections (lists & dictionaries) 35 | * If/else 36 | * Loops 37 | * Basic math 38 | * Functions 39 | * Errors & debugging 40 | 41 | * Students can read basic python scripts. 42 | 43 | * Students can solve simple problems with Python: 44 | * Finding duplicates in two lists. 45 | * Detecting if a word is a palindrome. 46 | * Detecting if two words are anagrams of each other. 47 | * Finding the most and least common elements in a list. 48 | * **Bonus:** writing a simple text-based rock paper scissors game. 49 | 50 | # Lesson Plan: 51 | 52 | Before starting the lesson write a broad version of the objectives somewhere that will remain visible to students throughout the day. Roughly: 53 | 54 | * Describe the software ecosystem/architecture of enterprise scale companies. 55 | * Describe the process of software development and the software lifecycle. 56 | * Describe why there are so many different programming languages, frameworks, and tools. 57 | * Define core programming concepts that appear in most programming languages (using Python as an example). 58 | * Write simple Python programs. 59 | 60 | _The goal in the morning is to get students talking and thinking about the big picture of programming, both in general and within the context of their company. Focus on asking questions and facilitating a discussion rather than leading a presentation. Your knowledge and ability to connect ideas will be more valuable than a list of important concepts. Said another way; focus on diagraming what the students tell you about and pushing them for more information, rather than hitting every little topic mentioned in the outline below._ 61 | 62 | ## Introductions (5-10 minutes) 63 | 64 | Try to be quick, encourage the students to be quick also. Ask every student to answer these questions, **starting with the instructor.** 65 | 66 | 1. What is your name. 67 | 2. What do you do here at SomeCompany. 68 | 3. What is one thing you hope to learn in this class. 69 | 70 | Make sure to tell people if they _will_ learn the thing they want to learn, especially if you don’t think it’s on the curriculum. **This is your best chance to set expectations.** 71 | 72 | **Try to memorize their names as well.** 73 | 74 | 75 | ## Set The Agenda and Atmosphere (5-10 minutes): 76 | 77 | * This is a class with a lot of different levels of experience, and a lot of beginners. 78 | * Please don’t belittle anyone for not already knowing something. 79 | * In general please be kind and compassionate in class. 80 | 81 | * Please ask lots of questions, and expect me to ask you a lot of questions. 82 | * I will be facilitating group discussions, pair shares, exercises, and maybe even cold calling you! 83 | * Don’t be afraid of being wrong, guessing then getting feedback is a great way to learn. 84 | * I love going on tangents, and I have a pretty strong breadth of knowledge. This class is meant to be valuable to _you_ so get your questions answered. 85 | * I may punt on some questions if we get TOOOOOO far afield. 86 | 87 | * The more you engage, the more you will learn. 88 | * If you wanted to come to class and passively absorb some tidbits from a slideshow, I am going to disappoint you, just a heads up 89 | 90 | * **Questions? Concerns? Thoughts?** 91 | 92 | In broad strokes, go over the agenda for the day. Use the objectives you wrote on the board somewhere as a guide for this. Here they are again: 93 | 94 | * Describe the software ecosystem/architecture of enterprise scale companies. 95 | * Describe the process of software development and the software lifecycle. 96 | * Describe why there are so many different programming languages, frameworks, and tools. 97 | * Define core programming concepts that appear in most programming languages (using Python as an example). 98 | * Write simple Python programs. 99 | * **Questions?** 100 | 101 | ## The Software Ecosystem (30-40 minutes) 102 | 103 | **During this exercise, you should be drawing on the whiteboard _constantly_.** The goal of this section is helping students understand the breadth and complexity of modern software ecosystems. Most importantly, helping them understand the parts of the business that THEY interact with, which is why you want to **continuously probe the students for more:** “What else does SomeCompany use? What would this connect to? Who uses this, where are they in the diagram? 104 | 105 | At a minimum, the following will probably come up so know how to put them on the board: 106 | 107 | * Websevers 108 | * DNS 109 | * Databases 110 | * Point of Sale Systems 111 | * Data Science / Machine Learning tools (data and compute) 112 | * Business Intelligence tools (e.g. Tableau) 113 | * “APIs” (they’re just other websevers!) 114 | 115 | **Okay Here’s the actual discussion walkthrough:** 116 | 117 | * Over the next 30-40 minutes we’re going to build a big picture of software, how it works, and the physical infrastructure involved. 118 | * We’re going to talk about a lot of things that basically every business does with software, and we’ll try and get some of the specifics of SomeCompany with your help. 119 | * We’re going to diagram as much as we can on the whiteboard. 120 | * Let’s start off simple: How does a user get to SomeCompany’s website? 121 | * User (phone/computer/tablet) makes types [www.SomeCompany.com](www.starbucks.com) into their browser 122 | * HTTP request gets sent it to SomeCompany webserver 123 | * Webserver responds, also using HTTP. 124 | * **Boom? Have we left anything out (all of networking)? Ask follow ups if no one answers:** 125 | * _How did the HTTP request know where to go? From [www.SomeCompany.com](www.starbucks.com) to this particular webserver?_ 126 | * _What if the user wants to log in? Would this be different? How?_ 127 | * _Are customers the only users of SomeCompany’ web systems?_ 128 | 129 | * **DNS**: The URL has to become an IP address, and SomeCompany probably operates their own DNS infrastructure. Possible they pay someone else (Cloudflare, NS1…) 130 | * At a minimum, SomeCompany has to have their IP addresses in DNS servers. 131 | * Those DNS servers communicate with other DNS infrastructure, mention ISP run, and other resolvers (maybe put them on the board in a different color) 132 | * _DNS is a whole big ecosystem, don’t get into TOO much depth_. 133 | 134 | * **Login:** 135 | * User needs to send data. 136 | * Server needs to… check that data against a database! 137 | * _So add the database to our diagram._ 138 | * **Most of the time, we stay logged in… how does this work?** 139 | * _Cookies (lots of tangents possible here, if you have time. Tracking cookies are always fun.)_ 140 | 141 | * **Databases & Data Warehouses:** 142 | * So, the website needs a database for users and other website data. 143 | * Other teams and departments probably need data too… 144 | * Often times DB’s will be separated by task. 145 | * Data warehouses for long term storage. 146 | * Analytics databases for common use. 147 | * ... 148 | * The data might be in very different formats in these databases for a variety of reasons like space efficiency or access speed. 149 | 150 | * **What about for internal tools? We all know a lot is hidden to a user of your website…** 151 | * _B.I. Tools probably come up here._ 152 | * _And/or some way for people to actually QUERY the databases._ 153 | * _Email maybe._ 154 | * _Point of Sales systems._ 155 | * _Encourage them to say more!!_ 156 | 157 | * **What about “Web APIs”? What are these?** 158 | * _Mostly just 3rd party web servers. You an add one._ 159 | 160 | * **What about data scientists? Where is there code running here?** 161 | * _Highlight the difference between something like fraud detection (live, always running) and report generation / data analysis._ 162 | * _Compute to train the model on AWS vs the running version of the trained model (webserver)_ 163 | * _Compute to train the models and crunch the numbers vs slide deck, charts, etc that is the deliverable for many data scientists._ 164 | 165 | * **Where the heck does all this data come from?** 166 | * _Point of sale._ 167 | * _Purchased data._ 168 | * _Painstaking data collection (forms, surveys, consumer research…)_ 169 | * _Website monitoring / tracking._ 170 | * _And… all this has to be run through software that converts it to a schema that your database can handle, so that it can be useful!_ 171 | 172 | * **What about “The Cloud”, how does that fit into all this?** 173 | * _Most of the services on the board are probably running on AWS or Azure, or something similar._ 174 | * _There might be one or several instances, possibly even one of more providers._ 175 | * _E.g. DNS might be with one “cloud provider” and your web servers might be on a separate cloud provider._ 176 | 177 | **This is a good time to give the students a quick break. Take 5-10. It should be about ~10:30am by now.** 178 | 179 | ## The Software Development Lifecycle (10-15 minutes) 180 | 181 | **In this section we’ll be expanding the diagram we already made, hopefully there is room. If not, try to leave some of the more critical things on the board. For example, the Web Servers.** 182 | 183 | * Version control is one of the most foundational pieces of infrastructure in software development. 184 | * **What is version control? Does anyone use it?** 185 | * Describe git, and github: 186 | * Git is VC software, github is a service built on that software to host code. 187 | * Keeping old versions, enabling rollback in case of bugs, enabling audits of old code. 188 | * It also has collaboration tools like branching so that many people can work on the same (large) codebase at once while stepping on eachother’s toes a bit less. 189 | 190 | * In their daily work, an engineer will typically start by pulling down any new code. 191 | * Then make changes locally. 192 | * Test it, code review, other process can happen. 193 | * Then push the code up to the repo. 194 | 195 | * **Does this mean the code on the webserver has changed?** (no) 196 | * When we push the code to GitHub, there still has to be a process to move that new code onto the servers where it will be executed. 197 | * This is “DevOps” and for a lot of companies this is mostly automated now—that automation is ITSELF software, which makes this kind of recursive and weird but bare with me... 198 | * Code gets pushed to github, a hook detects that push, that hook takes the code, and moves it to the web server, where it can now be executed. 199 | 200 | * Describe the differences between: Production / Staging / Dev / Test / Local 201 | * **Has anyone heard these terms used?** 202 | * **What do they mean?** 203 | 204 | * There are usually several different “environments” that this code runs through during a deployment. 205 | 206 | * Local: the programmers computer. Might have lots of differences between the production hardware, OS, and more. 207 | 208 | * Dev / Test: Available to programmers & QA engineers, closer to production hardware but at a much smaller scale. Used for devs to test things out, or possibly give demos of new features. 209 | 210 | * Staging: Typically not available to the public, but mirrors the production setup very closely at a smaller scale. Typically this is used for running automated tests just before deployment. 211 | 212 | ## The Purpose of Different Languages, and Different Kinds of Programming (20-30 minutes) 213 | 214 | **This section is to get students thinking about the breadth of software, but it is also to elucidate the fact that all these different subdomains share a lot in common. We’re going to be focused on learning those key foundational aspects of programming after lunch.** 215 | 216 | * **What IS a programming language?** 217 | * _You’ll get some interesting answers here…_ 218 | * _Help students see that it is more or less: text with special rules on how it must be formatted._ 219 | * _Rules help the “compiler” or “interpreter” understand and execute the code._ 220 | * _But most programs are also made with humans in mind: Other programmers must be able to read your code!!_ 221 | 222 | * **Who here speaks a programming language, even just a little?** 223 | * **Which one?** 224 | * **What do you use it for?** 225 | 226 | * **What languages have you heard of, besides the ones you’ve used?** 227 | * **What do you think it’s used for?** 228 | 229 | * _Be prepared here to discuss the different languages and their purpose. At a minimum you should expect the following to come up:_ 230 | 231 | * _Python (almost everything, “2nd best language for every task”)_ 232 | * _JavaScript (Websites, but increasingly a little more)_ 233 | * _Java / C# (Web infrastructure, games, enterprise)_ 234 | * _C / C++ (Systems, low level)_ 235 | * _SQL (totally different, just for getting data from a database!)_ 236 | * _HTML/CSS_ 237 | 238 | * _Bring up a few more than the students guess, unless they collectively get a lot._ 239 | * _The point is: There are about a zillion different kinds of programming languages._ 240 | 241 | * **Why are there so many different programming languages?** 242 | * _Different languages for different specialties within programming._ 243 | * _Which means: when someone says they are a “programmer” it can mean a ton of different things, from application engineering to systems engineering the daily work can be vastly different._ 244 | 245 | * Describe the difference between “declarative” languages, and “imperative” languages. 246 | * SQL, HTML, and CSS are all declarative: you describe what you want and the computer makes it happen, but the process of how it happens is invisible to you. 247 | * C. JS, Python are all imperative: You describe the steps that the computer will take to fetch or process the data. 248 | * It’s not always a clean hard-line distinction, some programs have aspects of both depending on where your abstractions start. E.g. JS almost feels declarative when you consider that the real executing code is Machine Code. 249 | 250 | * After lunch, we’re going to learn to write and execute simple programs in Python. 251 | * **Questions?** 252 | 253 | 254 | ## Environment Setup Help (Till Lunch) 255 | 256 | Students SHOULD have VS code setup, but that might not be the case. Make sure everyone has it, and direct them to install the [Python extension](https://marketplace.visualstudio.com/items?itemName=ms-python.python) if it is not already installed. Give the students a goal, execute this very simple program from within VS Code: 257 | 258 | ``` 259 | print(“hello world”) 260 | ``` 261 | 262 | **As a backup students can use repl.it instead. Not as ideal, since they won’t have their own work saved on their machine to take away from the class, but if firewall issues or something like that comes up, it’s better than nothing.** 263 | 264 | # Lunch Break 265 | 266 | _After lunch your goal should be getting out of lecture mode as fast as possible. There are both code reading and code writing exercises designed to help students learn these fundamental concepts without you just telling them. This content is utterly uninteresting as a lecture about rules and syntax and the differences between ‘expressions’, ‘statements’, and all that stuff._ 267 | 268 | _Tell them the absolute basics, then push them off the cliff. They’ll learn to fly or they’ll ask you for help and both are better than a boring lecture._ 269 | 270 | 271 | ## Programming Fundamentals (5-10 minutes) 272 | 273 | * Programming is always about data. 274 | * Fetching data. 275 | * Transforming data. 276 | * Processing & combining data. 277 | * Saving data. 278 | * _And that’s about it._ 279 | * **But what does data even mean? What kinds of data are there?** 280 | * _As long as students say something that has ever been on a computer… they are correct! Videos are data, images are data, text is data, numbers are data…._ 281 | 282 | * It sounds simple and in a way it is. Even very complex programs are made by combining simple building blocks. 283 | * Legos are a great metaphor, the game Minecraft is another good one: 284 | * From simple rules and simple atomic units (bricks) you can build huge and elegant masterworks. 285 | 286 | * All programming languages have ways to handle data and different data types. 287 | * Nearly all programming languages have the following: 288 | * Variables, control flow, functions. 289 | * _I say nearly because there are languages like CSS/HTML (no control flow, no variables) as well as languages like Prolog (no control flow, variables are… different)_ 290 | 291 | * We’re now going to examine these fundamentals in the context of Python. 292 | * Different languages have different syntax, different restrictions, and sometimes different data types. 293 | * But much of what we learn today will be the same in other languages, just like learning “grammar” is helpful in learning other human languages. 294 | 295 | ## Syntax and Basics By Example (30-40 minutes) 296 | 297 | _Work through the code-examples folder with the students. Encourage students to ask a lot of questions, live code changes that they request and run the samples. Ideally this shouldn’t take too long, so try to keep things moving._ 298 | 299 | _Tell the students we’re going to look at more realistic examples very soon, and focus on the syntax—this is like learning the alphabet before we read. “A makes the sounds ‘uhh’, ‘ay’ … etc.” This part can be painful, but we have to crawl before we can walk._ 300 | 301 | _The purpose of these examples is to:_ 302 | 303 | * Introduce syntax fundamentals 304 | * **Especially scope and whitespace, which so important in python!** 305 | * Introduce the idea of data types 306 | * Introduce variables 307 | * Describe how computers are absurdly “pedantic” 308 | * case sensitivity, 309 | * no ability to infer, 310 | * “the computer does exactly what you told it, not what you THINK you told it” 311 | * Introduce lists and dictionaries 312 | * A few builtin functions (append, get, len…) 313 | * Point students towards documentation for more 314 | * Introduce loops 315 | * Introduce if/elif/else 316 | * Introduce functions 317 | * **Quick break, ~5 minutes try not to lose too much momentum, but let students catch their breath.** 318 | 319 | 320 | ## Reading Code Exercises (~60 minutes) 321 | 322 | _Work through the reading-exercises folder with the students. Work through each code file one by one and:_ 323 | 324 | * **Work the clock**: set a reasonable amount of time and put a timer on the projector for students to see (5-10 minutes should be enough) 325 | * **Work in pairs or groups**: students need to practice explaining code to each other! 326 | * **Let them lead:** when time is up ask if anyone wants to describe the code. 327 | * Then ask for answers to the questions in the comments. 328 | * If everyone is confused, help them out by describing the code. 329 | 330 | **Take a longer break now, the students have earned it!** 331 | 332 | 333 | ## Writing Code Exercises (until there are 30-40 minutes left in class) 334 | 335 | _The class finishes with a lot of time for students to practice writing code. Have students work through the exercises in writing-exercises one by one. The order is frankly arbitrary, and if students want to work on them out of order based on their interest, that’s totally fine. Similarly, most students will probably not finish all 5 exercises and that’s also fine. If some students DO finish all the exercises before class ends you can set them up with harder problems on leetcode.com, codewars.com, hackerrank.com or something similar._ 336 | 337 | _Unlike the reading exercises, I suggest allowing students to have this block largely uninterrupted. If a handful of students are encountering a similar problem, bring the class together to look at a solution, then let them go back to work._ 338 | 339 | _Encourage students to work alone or in pairs, but not in groups of 3 or more. Before you unleash the class on the exercises, spend 5-10 minutes describing a good strategy for approaching these coding problems (more or less this is [Polya’s Method](https://math.berkeley.edu/~gmelvin/polya.pdf))_: 340 | 341 | * Step 1: Understand the problem. 342 | * Define the input and output carefully 343 | * Create examples / test cases 344 | * Give names to important concepts if necessary 345 | * Step 2: Make a plan 346 | * Use comments, or pseudocode on a whiteboard or paper 347 | * Make a diagram 348 | * Work backwards 349 | * Guess and check 350 | * Step 3: Enact the plan 351 | * Take your plan and translate it into code 352 | * This step is the easiest for folks who have already mastered their programming language 353 | * But it is hardest the first few times, since you’re learning the language 354 | * This is the part where the computers irritating pedanticness is felt most heavily. 355 | * Step 4: Revise and revisit 356 | * Did your plan work? 357 | * What specifically worked? What didn’t? 358 | * Ask yourself if you can break your code, are there edge cases you haven’t yet considered? 359 | * Ask how you can make it better (faster? more readable?) 360 | 361 | ## Review Two (or more) Solutions (with the last 30-40 minutes of class) 362 | 363 | * _Quickly poll the class to see who solved which problems_ 364 | * _Pick two of the problems such that a majority of the class solved at least one of them_ 365 | * _(most likely the first two problems!)_ 366 | * _Ask a student to demonstrate their solution_ 367 | * _Then you demonstrate the sample solution_ 368 | * _Thank the students, and release them back into the wild._ -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Programming Essentials Workshop 2 | 3 | The materials in this repository are designed for a full day workshop that introduces students to software and programming. This course targets absolute beginners who want to learn the basics of programming. This course assumes very little background knowledge. Before students start writing code the class will spend some time contextualizing the field of programming by discussing modern software ecosystems, and the software development lifecycle. 4 | 5 | The two primary goals of this course are: 1) Give students a "big picture" understanding of how software is used, especailly in corporate contexts. 2) Get students reading and writing simple Python programs. 6 | 7 | **Students in the class will learn about:** 8 | 9 | * Large scale software ecosystems: 10 | * What are the parts? (Webservers, email servers, databases and data warehouses, cloud compute for data science...) 11 | * How are they connected? 12 | * The software development lifecycle: 13 | * What does a "day in the life" of a software engineer look like? 14 | * How does code get deployed to all the parts mentioned above? 15 | * How do software teams manage their codebases? 16 | * How to write simple programs in Python. 17 | 18 | For more details on the course objectives and how they will be achieved, please see the [lesson plan](/lesson-plan.md). 19 | 20 | ## Using This Repository 21 | 22 | This repository has three main components: 23 | 24 | 1. The [lesson plan](/lesson-plan.md) 25 | 1. Several [code examples](/code-examples) demonstrating the basics of Python. 26 | 1. [Exercises](/exercises) for students to attempt during the workshop. 27 | 28 | For instructors, I suggest reading the lesson plan, which calls out when and how to use the code examples and exercises. For students, this repo will serve both as a helpful place to review the workshop as well as the starting point for all of the exercises. Students will be asked to copy and paste code from here in order to start the exercises. You may wish to save yourself a little time by clicking the green "clone or download" button on the upper-right side of this page, and download this repo to get all the examples and exercises on your own computer. 29 | 30 | For students who are already familiar with `git` and Github, you may wish to clone this repo in order to save some time copy/pasting the instructions. But honestly, if you're already familair with `git` and Github, you might find this course to be a little boring. 31 | 32 | ## Copyright and Licensing 33 | 34 | The purpose of this repository is purely educational. 35 | 36 | The information and code here is provided without warranty of any kind. 37 | 38 | Everything in this repo has been released to the public domain. You may use it for any purpose whatsoever, without restriction. 39 | 40 | ## Support Teb's Lab 41 | 42 | These materials were created by [Tyler Bettilyon](https://www.linkedin.com/in/tylerbettilyon/) and [Teb's Lab](https://tebs-lab.com). You can support the creation of more free, open source, public domain educational materials by sharing them with others, [subscribing to our newsletter](http://eepurl.com/dum8IP) or becoming a subscriber on [Patreon](https://www.patreon.com/tebsLab). --------------------------------------------------------------------------------