Giter Club home page Giter Club logo

project-vulcan's People

Contributors

dubway420 avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar

project-vulcan's Issues

Preparation 1: Installing Software

EDIT: if you have limited space on your computer, you can safely skip this homework and move onto issue #5

Before we get started, we're going to need to install a couple of software packages. The packages we will install are called Docker and Visual Studio Code. Head over to the websites for those packages and go ahead and install the version for your operating system.

Docker will allow us to create a virtual computer on our own machines which will provide a standardised environment for work. There's an old cliché in programming that the code one person produces runs differently (or not at all) on every computer it is deployed on. This is for a multitude of reasons - different operating systems, different versions of underlying software etc. As you can imagine, this isn't ideal and so this is where Docker images come in. They allow us to to have an exact duplicate of the working environment on each of our computers so that the code runs exactly the same.

image

In this project, we are going to be writing a lot of code and this is where Visual Studio Code comes in. This program is called an integrated development environment (IDE) which is just a fancy name for a program that allows us to read, write and edit code. It has a number of features which make the whole process easier, from highlighting to code completion.

When you have installed both VS Code and Docker you have completed this exercise.

Preparation 4: More on Types

In this assignment, we are going to learn some additional things about types in Python.

Let's fire up our Codespace from Issue #6. If you go to your branch, click <> Code and Codespaces, it should be there. It'll have some weird randomly generated name.

image

I have created two new files for this homework which are both on the original Homework branch. We need to 'checkout' these files.

The first thing you need to do is open up a terminal. Click the three dashes in the top left corner, go down to Terminal then select New Terminal. It should open a new terminal at the bottom of the screen.

We need to checkout the Homework branch to get the new files I have added:

git checkout Homework

You are now on the Homework branch and should be able to see two new files in the tree (task1.py and task2.py). We need to switch back to your branch and bring these files over. Enter the following into the terminal:

git checkout <your-branch-name>

replace with the name of your branch! Next, we want to bring those files over:

git checkout Homework task1.py task2.py

image

These files should now be visible in the file tree on the left. Open them up in turn, read through the instructions and attempt to complete the challenges it gives you. Any problems, comment below!

ONLY READ THE FOLLOWING AFTER ATTEMPTING TASK 2

You got an error didn't you? Something about not being able to concatenate str (strings) and int (integers). Don't worry, this was supposed to happen. Getting an error seems scary at first but they are normal part of life for any programmer. They are often easy to understand and fix. Sometimes, its a spelling mistake, a missing bracket or something else trivial. The error message will say the category (in this case, TypeError) as where in your python file the error is occurring (in this case on or around line 150). If you can't figure it out, the best bet is to copy and paste the error message into a search engine. Almost always, someone else will have had the same error as you and will have posted about it on StackOverflow or GitHub issues. Some friendly individual will probably have written an explanation with some easy fix. Overtime, you will get fewer and fewer errors in your code, or at least get better at fixing them. You can also send me a message, just be sure to communicate exactly how I can recreate the error and what you were trying to do.

Python wont let you concatenate some variable types. What we have to do is convert (or cast) the integer to a string before doing the concatenation.

number_first_string = str(number_first)

In the above line, we are telling Python that we want to cast the integer variable number_first to the type str (string) and then assign it to a new variable called number_first_string.

Now go back to the Python file and try Task 2 again with the knowledge you have learned here.

Preparation 5: Learning to Commit

Do you have issues with commitment? You won't after completing this homework!

image

In the last two homeworks, you modified three - example.py, task1.py and task.py. Notice that they are highlighted in the file tree in orange, meaning that they have uncommitted changes. To go back to our computer game metaphor, we have made progress in our game but we haven't made a save game. In Git parlance, we are going to make a commit.

It is good practice to make a commit after making a significant milestone or segment of progress (like completely a homework). You can make them as often or as infrequently as you like, but it's good to keep a regular schedule.

A commit is like a milestone involving several files of our choice. In the future, once we have made several subsequent commits involving these files, we will have the ability to return to (or 'checkout') any earlier commit at any time, just like loading up an old save game. It's like time travel, but for code.

The first thing to do is to look at the Source Control panel. You can switch to this clicking on the button the left (highlighted in red) or by pressing Ctrl+Shift+G. We should see three files which have been identified as having uncommitted changes - click the plus (+) button next to each one to (highlighted in yellow) to 'stage' these changes. Files which are staged are part of a 'package' ready to be committed. I give an example of a staged file with a blue arrow pointing to it in the below image.

image

Once all three files have been staged, we need to give to write a commit message in the box above the green button. Try to think of something meaningful to put in every commit message: this is a real art. In the image below I show some examples of very bad almost meaningless commits. Here we are committing the changes from the last two homeworks, so many enter something along those lines.

image

One all that is done, simply click the green button to make the commit. At this point, we have only made the commit 'locally' i.e. they only exist within your Codespace (or on your hard-disk if you are working on your computer). We now need to push these changes to the remote repository, that is the GitHub servers. To do this, simply click the Sync button which should now have appeared. A message should appear asking if it is OK to make a Push and Pull operation, to which you should say yes. Don't worry about what a Pull operation is at this point, but it is pretty much just the reverse of a Pull i.e. it brings any changes which might exist on the remote server to our local workspace (currently there are none).

image

And there we have it! You just made your first commit and pushed the changes to the remote server. This is no minor achievement, you have just learned how to do the most important task using Git. There are other things still to learn about using Git of course, but this is the biggest and most useful part.

The last thing in this homework to do is to go to the web page of the repository and see the changes appear (you need to be on your branch of course).

Preparation 6: Lists

Lists in Python are a type of variable that contains other variables. They are, as the name suggests, a list of variables. They are also an example of a type of data structure - a way for Python to store data.

An example of list is defined as follows:

list_first = [0, "one", 3.0]

In the above, we have a list variable named first_list which has three terms in it. Note that when defining a list, we encapsulate terms in square ([ ]) brackets. Note also that a list can contain variables of different types - in the above example, our list contains variables of the integer type (0), string type ("one"), and float (3.0).

Lists might seem simple (and they are) but we are going to introduce a few new concepts in this homework. These concepts are:

  • Indexing: the system of counting terms in things like lists.
  • Methods. These are built in functions that exist for some variables.

Let's start with indexing. The index is just the numbering system that we use for items in the list. The important thing to know about lists is that they are ordered i.e. the index of each item stays the same (unless we change it). Look at the list above: what is the index (number) of the item with the value of zero (0)? You'd think it would be one (1), right? Wrong! It is actually element zero (0) of the list. Yes, that's right - in Python we start counting at number zero (0) rather than one (1). The reasons for this are not important, you just have to remember it.

image

Now to talk about methods. Many variable types, such as lists, have a set of built-in methods. You can involve a method with the following syntax:

variable.method_name(argument1, argument2, ...)

For example, if we wanted to add an element with the value "next" to the end of list_first we would use the append method with "next" as the argument:

list_first.append("next")

What do you think will be the output of the following code?

print(list_first)

To explore this topic interactively and learn more about lists, checkout the task3.py & task4.py files that I have created. Load up your Codespace, ensure you are on your branch and get the file with the following command in the terminal:

git checkout Homework task3.py task4.py

ONLY READ THE FOLLOWING AFTER ATTEMPTING TASK 3

If you did something similar to the following:

print("The third element of the list is", list_first[3])

You got an error saying something like:

IndexError: list index out of range

What's going on here? Let's break down the index of each element in this list:

list_first = [0, "one", 3.0]
index:

[0] = 0
[1] = "one"
[2] = 3.0

As you can see, there is no element [3]. There might 3 elements, but the first one is indexed as zero...so the final element is actually [2]. So, you got an IndexError saying that you are trying to access an element that is outside of the range of this list. If this seems extremely frustrating and confusing, that's because it is. I have been coding for years and it still gets me. Luckily, there are a few tricks we can use to avoid this which I will discuss in the next task.

image

ONLY READ THE FOLLOWING AFTER ATTEMPTING TASK 4

As you've probably figured out, using the index [-1] accesses the final element in the list, regardless of how many elements are in it. It is a safe way to access the final element of a list that you might be changing the size. We can use [-2] to get the last-but-one element and so on.

There are lots of cool thing you can do with lists which we'll touch on in further homeworks. You can for instance nest loops inside other loops i.e. you can put lists inside lists to make two dimensional lists...in fact you put put lists inside the lists inside other lists ... and so on to the maximum depth only limited by the RAM on the computer you are working on.

image

Another thing we can do with lists is take slices from them - i.e. we can cut bits of them out and do stuff with it. This is a bit tricky though as the positions you could from and end at ... changes. Yeah it's tricky, we'll come back to that.

CONCLUDING REMARKS

If you have made it this far, I just want to say thank you and well done. You've learned the core skills of using Python and built a solid foundation for using this programming language to do some really great stuff. A lot of this stuff is a bit tricky to get your head around, but by getting this far you have invested in your skills and you should be proud of yourself. Keep it up and we will do great things!

Preparation 3: Basic Python Programming

Overview

In this homework, we are going to learn some Python skills that you might use throughout this project. The first things you will learn about are:

  • Commenting and uncommenting lines of code
  • Defining and using variables
  • Printing statements to the terminal

These are some very basic skills and they aren't hard to learn, but they are fundamental tools to use in python.

Commenting

Commenting is very important for a number of reasons. Any line that starts with a hash (#) symbol is essentially ignored by Python, it is only to be read by human beings (like you!). It might be instructions to the user, an explanation or a reminder to do something etc. Another reason to comment out a line of code is that we might want to try out not running a line of code. Perhaps we want to temporarily disable some feature we've added, but we don't want to delete it outright - we just toggle it off by putting a hash at the start of the line. See the two lines of code below. One of them is commented out, one is not. Can you tell which is which? What would we do if we wanted to toggle a line on or off?

# print("This is one thing we could do")
print("This is another")

Have you heard the saying that most of the human genome doesn't actually do anything and is just junk that doesn't do anything? A way to think of this is that most of our DNA is commented out: it's encoded in there, we can read it, but it effectively does nothing.

Regular (uncommented) lines

If a line of a Python file is not commented then you are telling Python to run this code. For this to happen successfully when you come to execute your Python file, it needs to be valid i.e. it has to follow a very specific set of rules. Look at the line of code below:

prnt("this is a print statement")

You can probably guess what I wanted to do here, but I have made a mistake. Now you and I may understand the meaning of this line, but to Python this might as well be completely random bashings of the keyboard. It has to be perfectly correct for Python to understand and execute your code.

If the cursor (that little vertical flashing line) is on a line and you want to toggle it as commented/uncommented, you can press Ctrl+/ or you can simply add or delete a hash (#).

Defining variables

Variables are bits of data that can be used by our Python program. Variables have a range of different types depending on what kind of data we want to store in them. For example, if we wanted to store a whole number, we would use a variable of the type integer (or int). See the line below of how an integer variable with the name number would be defined with a value of 3:

number = 3

Some important things to note here, forgive me if these are obvious to you:

  • We define the name of the variable by the word on the left, in the above case it is number. When we want to access this variable later in the code, we can use this name again to access this variable.
  • We tell Python that we are defining a variable through use of the equals symbol (=)
  • The text on the right of the equals symbol is what value we want to assign this variable. In this case, we are giving it an integer value of 3.

Now we are quite lucky in Python that we don't have to state the type of a variable, it is implied by the value we give it. In the above case, Python knows that we want the variable named number to be of type integer because we are giving it a round number as its assigned value.

Lets look at another example:

words = "This is a variable of type string"

We've defined a new variable, this time called words. In this case, the value is not a number, but a set of words contained within inverted commas. If you put anything within inverted commas in Python, you are telling it to essentially store this as text, just like a human would read. This variable is of type string. What's the difference between a string and a commented out line as seen above? The key difference is that a commented out line is essentially ignored by Python, whereas a string is stored allowing us to do something with it later. For example, we can use them as part of a print statement:

print(words)

What would happen if we ran the above line in Python?

print("words")

How about this one? What's the difference? Latter on you can try both and see what happens.

Print statements

The print statement is what is called a built in function in Python. We will go into detail as to what exactly a function is in Python, but for now we will just say it is a command to do something specific. In this case, the print function tells us Python to write something to the terminal. As I understand it, in the olden days when code was written on bunch cards, such a function as this gained the name print because it was used to print to the screen. It is still very useful today for a range of reasons such as updating the user at runtime of the progress of the program, outputting data and is wildly used by stubborn/lazy programmers (including me) in a process called debugging (figuring out why something's gone wrong).

image

Functions are used in a very specific way: we write the name of the function (in this case it is print) then we add some rounded brackets and place an argument inside it. Essentially the argument is us telling the function what we want it to do:

print("This string is entered as an argument of a print function")

Above, we are giving the print function an argument of a directly defined string. Depending on the exact function we are using, we may be able to define it more than one argument, there may be optional arguments, or it might not need an argument at all. For example, both of the below lines of code are valid. What do you think they do?

print()

print("Hello", "Goodbye")

words of encouragement

All of this might seem a bit overwhelming, especially if this is your first foray into the world of programming. There's lots of weird phrases, everything looks a bit alien and you're afraid of doing it wrong. This is normal and there really isn't anything to worry about. If you get stuck, ask me, there really are no stupid questions here.

The thing to remember is that you can't strictly do programming wrong or break it in a permanent way. You can always go back to an earlier version of your code where it worked and start again from there, or you can comment bits out that may be breaking it. It's just like in a computer game when you lose, you can just start again from the last save game.

image

The actual homework assignment

So what are you actually going to do in this homework assignment? The first thing you are going to do is create a Codespace in GitHub - this is like a virtual environment that we discussed in Issue #2 using Docker. The first thing you want to do is switch over to your own branch that you made during Issue #5. You can do this from the main repo page.

image

Next click the <> Code button (blue), then the Codespaces tab (yellow), then finally the plus symbol (+) to create a new Codespace on this branch.

image

After some set up screens, you should be prompted to install some extensions: I'd recommend accepting for the Python one, but the Pylint one has caused me nothing but annoyance. YMMV.

image

Finally, you should see a new window similar to what is shown above. If you followed the instructions of Issue#2, this window might look awfully familiar to you, almost like it is Visual Studio Code … in a browser. On the left hand side of the page, you should see the project tree this is all the files in the branch of the repository you just selected. Click on the file named example.py (yellow) which should open it up in the main panel of the screen. Note that the file extension (.py) denotes this to be a Python file. Your homework assignment is to read through this file and follow the instructions. Note that you can run this Python file at any time by pressing the play button (⏵) that is in the top right hand side of the screen. If you have read and understood everything above, this homework assignment should be a complete doddle.

Good luck!

Preparation 2: Create your own branch

Git repositories such as this one are usually divided into branches. You can probably guess what a branch is from the name - it's a splitting off of the code along another path. To use a gaming analogy, different branches can be thought of as different play throughs of the same game. Of course we can go back to an earlier saved game and start a new branch from there, maybe going a completely different direction. The big difference is that diverging Git branches can be merged together again later, but we'll talk about that later.

Git branches allow us to do a few useful things which you can probably guess a few of. They allow us to:

  • Test out different approaches to a problem
  • Work on separate issues without them causing conflicts
  • Allow us to do some exploration and try out "what ifs"

If you look on the main page of this repository, you should see that you are currently viewing the 'main' branch of the repository. The main page is where we usually put "finished work".

image

You are now going to create your own branch. Click on the button highlighted in the previous image and click 'view all branches' which should lead you to a new page. On this new page, click 'New Branch'. In the 'New branch name' field, enter something like your name (it doesn't matter what you call it as long as you remember).

image

Under Source, make sure you select the 'Homework' branch, then select 'Create new branch'.

image

Congratulations! You've just created your own branch in a Git project! In the next project we will load the branch into a codespace and actually do some coding.

Preparation 7: Booleans, imports and more on lists

Quick Start

If you want to jump straight into the code, simply execute the following command in the terminal to import the relevant python files.

git checkout Homework task5.py task6.py

Homework Notes

In this homework, we will learn about another variable type: Booleans. They can have only one of two values - True & False. Secondly, we are going to introduce the concept of the import statement.. We're also going to be doing some more stuff with lists and also introduce a new built-in function called len which allows us to count the elements in a list.

Booleans

Let's start with Booleans. There are a couple of ways to define a Boolean: directly, or with logic.

Booleans - direct definition

We directly define a Boolean in this example:

boolean_first = True

Note that the True or False statement must be without inverted commas (that would be a string) and with a capital first letter. For reasons we wont go into, strings (regardless of their value) are almost always True. If this is confusing and doesn't make sense, don't worry, we'll go into more later.

image

Booleans - with logic

You may be familiar with the following comparison operators:

  • > Greater than
  • < Less than
  • >= Greater than or equal to
  • <= Less than or equal to

In Python, there are a couple more which are important:

  • == Equal to
  • != Not equal to

Note that Equal to requires a double equal sign. This is to differentiate it from the definition operator which involves just a single equals sign (=).

Python import statement

In Python (and most other programming languages) we don't have to have all the code we are going to use in a single file. We can import functionality from another Python file. This Python file might not be written by us. In fact, we might never actually read this file or communicate with its author, we just know that we need it and how to use it.

image

Think of cars travelling around on roads throughout the world. Millions of cars are moving right now, each having some kind of engine inside producing movement. How many of the drivers of these cars know how the engine inside works? Or any of the other components for that matter. Most just know that there's an accelerator pedal, brake and steering wheel which when used have a predictable effect on the behaviour of the car. For all intents-and-purposes, the engine and other mechanical components are a magical black box with controls on the outside that are used to get some useful output. In a sense, when we use a car we are importing the functionality of an engine into our vehicle and then using it - they allow us to keep standardised functionality under the hood and away from every day work.

In this homework assignment, you are defining a variable in one file (in this case a list of Booleans in task5.py) and importing it into a second file (task6.py). We are going to need some Booleans for task 6: we could define some new ones, but we already have a list of them from task5, so why not use those?

The syntax of an import statement is as follows:

from module import variable/function

The module is just another file or a built-in module that we just need the name of (we'll cover this, don't worry. In further assignments, we will look into how to import a wider variety of variables, functions and other things that we can use.

Get Hard Disk

We need a hard disk to store the dataset. The largest dataset is 5.5TB in size, with smaller ones being 1.8TB and 37GB.

I am open to suggestions of which disk(s) to get. Please post links below.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.