Live Coding Wk1 – Lecture1 – Introduction to the Course¶
We want to start getting you into the habit of having coding examples for the lectures, although we haven’t covered enough to discuss anything in detail.
Copyright By PowCoder代写 加微信 powcoder
Instead, we are going to use python to fact check ourselves for the calculation of course grades.
The Problem: Making sure the Course Math is correct¶
This seems basic right? It kind of has to be at this point, since we can’t bore you with the uses of Machine Learning Algorithms, pretty graphs or RSA security yet. So why do we care about a problem as simple as making sure our calculations for your course grades are correct? To make sure we aren’t providing incorrect information of course! How confident are we that our math is correct? We are willing to test it live in front of you. What could go wrong?
Detour: Using JupyterLab¶
What you are seeing right now (in the lecture at least) is the JupyterLab application. We will be using this for labs, assignments, and exams. While alternatives such as PyCharm and JupyterNotebook exist, we will be using JupyterLab exclusively. If you use one of the others, you are on your own!
Before we get into the course math, lets make sure we can use the program. This will also be covered in the first lab, but we will quickly go over it here.
# This is a Code Block.
# You also have markdown blocks, which is the pretty text above and below.
# It makes it much easier to read and digest information.
# Code blocks can be run, as you will see with the number to the left
# The number defines in what place it was run. Blocks are entered as a single item into the background kernel.
# Run the block by pressing the |> button above, or `Shift+Enter`
Notice in the above, the number will show up when you run it, and you can run the same block multiple times!
This is a _raw text_ block. Nothing is fancy, and it cannot be run.
We will use these when we want you to answer a question using text.
When you try to run the block, no numbers to the left, or output/processing will occur.
With that, lets get started
Coding: Fact Checking Time¶
We want to do a couple of simple items. For those who have coded in python before, this will be super simple. For those who have coded in Java or other Object-Orientated langauges, this will be somewhat simple. For those who have never coded before, this will be an easy introduction.
The idea of coding is covered in the lab this week (Lab01), so don’t stress if you are unsure of anything going on!
Does our assessment marks add up?¶
Lets start simple, and work out how many different ways, and in how many “lines of code”, we can calculate the sum of our assessment marks.
With the knowledge of how that works, lets write a function to make it easy to calculate someone’s final score based on their marks
Discussion Point: Why would we use a function here?
Discussion notes here
How could we extend the function to take into account the final grade someone might receive? ie: Distinction grade
How could we extend the function to take into account a student receiving a supplementary exam?
Comments, Comments Comments¶
We have three versions above, however what happens if we have thought of some super fancy (read: unusual) way of doing something, that from a glance someone else won’t understand? Answer: We need to comment our code!
There is a wonderful guide to doing this here, however we are going to stick to one main reason:
Don’t make life difficult for tutors and markers. They can be less kind with marks if you make it harder for them to mark.
Case in point: If you can’t completely answer a question in an exam, but have a half answer with comments on what you were trying to do and what went wrong, you will receive better marks than a half answer with no comments or an answer that doesn’t work at all.
How to Comment¶
# Shocking Right
# This could be considered a multiline comment
# However, the triple-quote comment actually acts as an unreferenced string,
# so it will be printed at times.
# We prefer the single line with hashes
# The triple-quote comment can be turned into a doc-string.
# See: https://www.python.org/dev/peps/pep-0257/
Good comments vs Bad comments¶
While the general rule of comment EVERYTHING can generally apply, there is a couple of rules we should abide by:
Avoid Smelly Code
Avoid Rude Comments
Lets talk about those quickly:
With that out of the way, now there are no excuses for not writing comments. Practice makes perfect! Make sure you comment the above.
That is enough for this time. See you all at the next lecture!
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com