We reviewed our general approach to solving a large problem with our example of cleaning a whole house. The thought of cleaning each room in the entire house is overwhelming, not for long!. First, ask questions: what is the problem? are there any special cases? Next, look for familiar things: if you have solved a similar problem, see if that solution can apply to the new problem. Thirdly, divide and conquer: to make it seem more manageable, we strategized on how to break up the large task into smaller, more manageable ones. Finally, make a plan (or algorithm): make a plan to tackle the new subsets of problems that make up the larger one; start at a subtask, finish it, then move on to the next; until the whole task is completed.
I'm thinking of a number... Choose a number between 1 and 20. If your first guess was in the middle, that was a great start! Then I could say if your guess was lower or higher than the number I'm thinking of. If you continue with using that method (start in the middle of the range of numbers), then you will guess correctly, much faster than simply guessing : is it one? is it two? is it three? and so on, or guessing numbers randomly. Take a look at the search tree below. The tree has a range of 15.
Every node in the tree has a value. Do you see a pattern? The subtree to the right of its node is greater than (>) its parent nodes value. The subtree to the left of its node is less than (<) its parent nodes value.
From here, we worked to create a random number guessing game in Python. The computer randomly chooses from a range of values, and the user tries to guess it. The bigger the range of values, the more you see how effective using the binary search method is. So, you can start to see how computers can handle large amounts of data with some simple tricks. Handling data will be a major theme in the coming weeks. Below is the gist:
We'll come back to this concept later... We will actually build a binary search program!
Assignment One: Try making this program continuous by adding a while loop.
So, What is technology? Is a chair or table technology? How about a sink? The answer is, all those items are technology! Technology are things created by humans to make our lives easier and/or solve problems. Some technology comes with instructions. For instance, new toys (e.g. Legos), bicycles, etc. come with instructions on how to put it together and how it works. Some technology, like phones, computers, iPads come with directions already inside of it. Someone (a person) had to write those directions (instructions) to tell that technology what to do. This is known as a computer program, step-by-step instructions on what to do. Computers only do what they are told to do! We talked about the difference between hardware (the physical stuff) and software (games/programs). We drew a computer on a piece of paper and labeled its parts. We defined which parts of the computer are input devices and which parts are output devices. To get used to telling a computer what to do and to further our learning in computational thinking, we started creating instructions for a robot to carry out, using the app, Lightbot.
We discussed the steps involved to make a peanut butter and jelly sandwich! We talked about how together, these steps make up a sequence of instructions. If these steps are followed, you end up with the result of having a pb&j sandwich. You can also call this an algorithm. An algorithm is step-by-step instructions that are followed to complete a task or solve a problem.
A Python dictionary (or MAP) is a collection of key-value pairs. In other words, think of Python dictionaries as glossaries or dictionaries in the real world. In a glossary or dictionary, you have words that each have their own meaning. To relate it to a Python dictionary, the dictionary word is the key and the meaning of the word is the value. We started with a class exercise to gather our data (or information). We gathered basic information about one another. The keys were categories like "last_name", "favorite_food", "lucky_number", etc. The answers to each question is the value.
Here's an example:
To relate the accessibility of Python dictionaries, consider an example in the real-world: You are searching for one word in a very large dictionary, glossary, or encyclopedia. You COULD search each word starting from the beginning (this would take quite a while). OR you could use different search methods: Look up the starting letter of the word (or key); this narrows your search down a bit. Now, you can just search for the word (key) in that selection to get its VALUE.
Assignment Two: Make an interactive program where a user can input their information from prompts by the computer. After the user types in their responses, those values are automatically added to a dictionary.
We started with a jumbled set of steps to complete the task of planting a seed. We arranged the steps in the order that made the most steps. We found that we could omit certain steps, because they did not help in completing the task. We then reviewed procedures form Lightbot. Procedures in Lightbot are just like functions used in computer programming. If you recognize a pattern, go ahead and make that pattern part of a procedure, or function. You can then reuse the procedures to use less instructions to get to the end result thus, making the overall set of steps more efficient!
What happens when you fire up your favorite program or game? Fetch, Decode Execute! We simulated what happens inside of a computer by playing the parts of a program, bus, and CPU (central processing unit). The Bus connects all the components of a computer, the program contains a list of instructions that perform some action, and the CPU is the "brain" of the computer; it carries out the program's instructions. This was our watered down process: CPU tells the bus to fetch the instructions from the program; the program gives the instructions to the bus; the bus gives the instructions to the CPU; then, the CPU decodes and executes (carries out) those instructions! This Fetch, Decode, Execute cycle happens from the moment you power on your machine. We are able to get the computers increasingly efficient at this process.
You can 'store' a set of dictionaries in a list or a list of items as a value in a dictionary. Remember lists?! "Yes!"... Good! We stored our freshly made dictionaries for each classmate from last week into a Python list. This method is called nesting. Another neat trick, spreading a program you made across several different programs. You performed something like this when you made the random number game program a couple weeks ago and when we built programs using the turtle module. You simply import your program:
from dictionary import *
Remember, once you type this in a new program, you can utilize everything you wrote in the program you imported; eliminating having to write the same things over again. I say "more abstraction", because with nesting you can hide certain details of the data inside of each dictionary; moreover, when you import a program, you can use data and functions from that program without having to 'muck up the waters' with code in this new file.
Assignment Three: try making a loop to add all your dictionaries into the list. Next week, we'll compare tuples and look into defining our own functions and loops to make things way easier.
We discussed what conditions and events are in real life and related it to making computer programs. "IF you eat all of your vegetables, THEN you can have desert" -sound familiar? This condition statement follows events and conditions found in programming. We worked on making a program in Hopscotch to touch on the concepts: events, sequence, loops, and ranges!
Recall from Week two and three: we have already made a few dictionaries and are familiar with how to access information from them. Anytime you want more than one value associated with a key, go ahead and nest a list inside that dictionary. We completed a good example of how to do this. Consider describing a pizza someone wants to order. Sure if you used a list, you could store a list of the pizza toppings; however, you can use a dictionary to effectively describe absolutely everything on the pizza. For our example, tow kinds of information are being stored for each pizza; type of crust and a list of toppings.
Here's the gist:
Included in the gist is our example of the favorite programming languages poll; now, with nested lists.
Below, the slides from this class if you want a little review with some nice visuals.
Assignment Four: Make your pizza program interactive. We had nice practice with this last year in our grocery list program. Have your program request user input to build a pizza using while loops. Ideally, you can pass your program to someone to build their own pizza and see the type of pizza they built looped back to them. Next week we'll finish up nesting and become masters at user input and while loops!
To further engrain efficiency and to appreciate advancements of computer hardware, we discussed the first computers, Tally Sticks. Early computers were tools used by humans to help with math. In the instance of tally sticks, these tools helped people count beyond their inherited method (fingers) before history was recorded! Our discussion included more advanced tools from the abacus, to the Babbage machine, to the first commercial computers, like the ENIAC.
We focused on the main components of computer hardware. The vacuum tube in commercial computers was replaced by the transistor, considered the building blocks of computers. We learned connecting transistors can make circuits. When we miniaturize these, we make microchips, which are the main components of computer hardware today. To gain an understanding of how this works, we learned about different switching devices that make up circuits. These included binary logic gates, AND; OR; and NOT gates. These can only have two possible input and output values, ON or OFF (hence the name binary). We created virtual logic gates using the app, Circuit Coder and we combined the gates to create circuits. We continued our discussion of binary by learning the binary number system. Think of binary as the language computers "speak". Here's an example of the binary flashcards we made:
We ended the class discussing what we've learned so far about programming (coding). We wrote our first program in a programming language, Python. The program was the classic, "hello world!". When the program is run, we have the computer say "hello world!". We related the parts of this program to the apps we have used so far, Lightbot and Hopscotch; highlighting procedures in Lightbot and giving instructions for the computer to carry out, step-by-step. We took this program a step further by adding variables and loops to further relate what we have learned so far in the class.
Below, is a gist from GitHub:
Writing interactive programs are fun and engaging! So let's become gurus at this!
Take a look at the gist we completed during class:
To familiarize ourselves with more concepts in programming, we made a simple program that takes input from a user and calculates the result. After we finished, we then made a program draw out the result using a Python module called, turtle.py
Assignment Five: Now that we know all about user input, revisit the pizza.py program. Make it a goal to pass your program to a friend and have them build their own pizza by typing in what they want. Once they finish, your program should loop through the new nested dictionary to show them the pizza they just built! BONUS Make sure you have a GitHub account that you can log in to. Extra bonus: upload your interactive pizza program to your own repository on GitHub. If you need help, check out the blog, http://blog.techemstudios.com/github-part-one.html or ask a question on Slack.
Assignment Six: See if you can add to the code we worked on in class to have the program ask for each user's name. A bonus would be to have each user's input stored in separate lists.
Remember, to download Python at home to practice outside of class, visit https://www.python.org/
In most programs,
while loops are used to keep a program running, as long as certain conditions are true. We started out with a simple counting program that starts counting from a number (adds to the number). Python will keep adding to the number until it is less than or equal to a certain number. Then we added to the program, a
while loop and
continue. Once, Python runs through the code in the loop once. When it comes to the
continue statement, Python again starts from the beginning of the loop. This process is repeated until the number we specify is finally reached. Some of you noticed that this program could be useful to mock as a timer in a game!
current_number = 0 while current_number <= 10: current_number += 1 if current_number % 2 == 0: continue print(current_number)
In the counting program, we went over a new operator in Python, modulo. This operation performs division of two numbers, but returns the remainder.
Check out the slides from today's class:
Assignment Seven: Write a program using a while loop that asks for user input to fill in a dictionary. In class, we did this to fill a list. The dictionary can be anything you want it to be! Look earlier in this post to get some review on dictionaries if you need to. Remember to use Slack if you have any questions!
Or object-oriented development(OOD) has the main idea of viewing a complex system as being a collection of simpler objects that communicate with each other. This is one of the most effective practices in writing software and is great for modeling occurences in the real-world. We quickly went through some vocabulary we'll find in OOP: Classes, Objects, Attributes, Methods, Instantiation, etc. Instead of getting bogged down in definitions, we took a look at a few examples.
When you think of the term, "vehicle" you might think of it as something that you can use to take you somewhere, i.e. a car, boat, or bicycle. Well, all these have attributes that are little different, but they are similar in that they are considered a vehicle. When we compare the car and the bicycle to the boat, we can say the car and bicycle are different from the boat, because they are "wheeled" vehicles. We can compare the car to the bicycle and see that one requires gas and the other doesn't. We can go further and compare cars to one another; some are SUVs, others are sedans and so on. Each type of car has their own unique properties and things it can do, but their similarities can be traced back to being a general car, wheeled vehicle (like a bike) and a vehicle (like a boat). So, you can see how we can model almost any real-world thing using this approach. That can be a lot to follow, so here's the same example displayed as picture:
We took a look at another example, where we compared a dog to a sidewalk. How can they be similar?! Well, both are things or nouns. In Python, we call them objects. We categorized this example further using a similar approach as before. We started with the category (or class) "Things" and created sub-classes. When we define a class, we tell Python what general behavior all the sub-classes and objects will have. Objects have their own properties and functions. A dog is living so it is part of the class Animate. A sidewalk or a dog's chew toy are non-living, so it is part of the class Inanimate. We put this example to the test by creating and defining a class for a dog (in general) in Python.
Assignment Eight: Try categorizing something you collect or interests you by defining it in a class and use an example to test some of the methods and attributes you made that make up that class. You can model it from the gist example we worked on in class. Some of you started this by creating classes that involved your favorite games such as, HalfLife and Overwatch.
We created a function in one Python file, saved it, then used it by making its function call in a separate file. This practices becomes very useful when working on a large project, such as a website application or a game. Having a large list of functions in one file, keeps you from 'mucking' up other files you are working in. All you have to do is import that filename in the one you're working in; keeping your code neat and organized. We call the import file (or files), modules.
We are comfortable with making our own functions, using our own modules, condition blocks, for and while loops (and how to stop while loops). So, let's create text adventure games utilizing these techniques! Students got started with sketching out ideas and making decision trees on paper. Scenarios included HalfLife game adventures and escaping from dangerous houses! We created directories and subdirectories, where we'll store function we'll use to later import and to organize or code as a whole.
Assignment Nine: Brainstorm ways on how your decision flow of your text adventure will pan out by sketching them on a sheet of paper and think about how you'll organize your code using the module techniques we learned today.