Skip to content

code1161 #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# CODE1161 - [your name here]

# CODE1161 - wukai kong
You can see lots of other course related stuff [here](https://notionparallax.co.uk/CODE1161).

![a photo of me](mugshot.png)
1 change: 1 addition & 0 deletions Wukai_is_cool.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
wukai is cool
16 changes: 8 additions & 8 deletions aboutMe.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: Ben Doherty
studentNumber: z1234567
gitHubUsername: notionparallax
stackoverflow: http://stackoverflow.com/users/1835727/ben
mediumUsername: notionparallax
unswEmail: noIdea@unsw.edu.au
realEmailFirstBit: ben # this avoids spam
realEmailOtherBit: @notionparallax.co.uk
name: wukai kong
studentNumber: z5155304
gitHubUsername: wukaicharlott
stackoverflow: https://stackoverflow.com/users/story/7650508
mediumUsername: kongwukai
unswEmail: z5155304@unsw.edu.au
realEmailFirstBit: k291973591 # this avoids spam
realEmailOtherBit: @gmail.com
Binary file modified mugshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 49 additions & 0 deletions new_exercise_getter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# -*- coding: UTF-8 -*-
"""Gets updated version of exercises.

Checks for existing version and won't overwrite.
"""
import os
import requests

LOCAL = os.path.dirname(os.path.realpath(__file__))


def get_the_updates():
"""Decide if the other functions should download each file."""
base = ("https://raw.githubusercontent.com/"
"notionparallax/code1161base/master")
new_files = [
"/week8/exercise1.py",
"/week8/tests.py"
""
]

for f in new_files:
save_path = "./" + f
if not os.path.isfile(save_path) and f is not "":
url = base + f
print("downloading", url)
download_and_save(url, save_path)
elif f is "":
pass # do nothing, it's padding
else:
print("You already have {f}".format(f=f))
print("If you really want to update that file, "
"delete it locally and rerun this script.")


def get_file_text(url):
"""Pull the raw file and return it as a string."""
r = requests.get(url)
return r.text.encode('utf-8')


def download_and_save(url, save_path):
"""Save a string as a file."""
f = open(os.path.join(LOCAL, save_path), 'w')
f.write(get_file_text(url))
f.close()


get_the_updates()
1 change: 1 addition & 0 deletions week1/_checkID
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
9f5eb95820e9475f8e7967708c08fadd
2 changes: 2 additions & 0 deletions week1/_requestsWorking
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Let's test Python and Requests:
***************************************** ** Python and requests are working! ** ** All hail his noodly appendage! ** *****************************************
19 changes: 11 additions & 8 deletions week1/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from __future__ import print_function
import sys
import os
sys.path.append(os.path.dirname(os.path.realpath(__file__))[:-5])
sys.path.append(os.path.dirname(os.path.dirname(__file__)))
from codeHelpers import test

WEEK_NUMBER = 1
Expand All @@ -18,11 +18,11 @@ def isThereAnID(path_to_code_to_check):
"""Check that this test is being run on a VM."""
try:
place = os.path.join(path_to_code_to_check, '_checkID')
# print("looking in {}".format(place))
# print("LOCAL", LOCAL, "\nCWD", CWD)
print("looking in {}".format(place))
print("LOCAL", LOCAL, "\nCWD", CWD)
f = open(place, 'r')
contents = f.read()
# print("contents", contents)
print("contents", contents)
return len(contents) > 8
except Exception:
print("TIP: Have you run pytest.py yet?")
Expand Down Expand Up @@ -52,23 +52,26 @@ def isRequestsWorking(path_to_code_to_check):
return False


def theTests(path_to_code_to_check=""):
def theTests(path_to_code_to_check="."):
"""Run the tests.

This is the main function, it contains all the tests for the week.
"""
print("\nWelcome to week {}!".format(WEEK_NUMBER))
print("Let's check that everything is set up.\n")

path = "{}/week{}/".format(path_to_code_to_check, WEEK_NUMBER)
testResults = []
testResults.append(
test(isThereAnID(path_to_code_to_check),
test(isThereAnID(path),
"Exercise 1: Test that your VM is working"))
testResults.append(
test(isRequestsWorking(path_to_code_to_check),
test(isRequestsWorking(path),
"Exercise 1: Test your connection to the internet"))

return {"of_total": sum(testResults), "mark": len(testResults)}
return {"of_total": len(testResults),
"mark": sum(testResults),
"results": testResults}


if __name__ == "__main__":
Expand Down
83 changes: 83 additions & 0 deletions week2/exercise0.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# -*- coding: UTF-8 -*-
"""Modify each function until the tests pass."""
from __future__ import division
from __future__ import print_function


def add_5(a_number):
"""Return a number that is 5 bigger than number given.

This isn't a trick!
First thing to do is to remove the pass. That's just tellign python that
the empty block is intentional - it's python's "this page is intentionally
left blank"
Then you need to:
return a_number plus five
except expressed in python, not english
"""
pass


def adder(a_number, another_number):
"""Add two numbers.

Same as above, but with any two numbers.
"""
pass


def shout(a_string):
"""Return a string in uppercase.

look up the docs for string methods. Either in the official docs, here:
https://docs.python.org/2/library/string.html
or in any of the million places that google will give you.
"python make a string uppercase" is a good starting search query.
"""
pass


def really_shout(a_string):
"""Return a string in uppercase, with an exclamation mark on the end.

In the spirit of being DRY (don't repeat yourself) reuse the shout function
from above.
Look up how to 'concatinate' strings to make this happen.
"""
pass


def minitest(f, args, expected):
"""Run a function with a list of args and print a response.

This is a helper. Don't edit it.
"""
result = f(*args)
template = "expect {name}({args}) == {expected} => {result}"
print(template.format(name=f.__name__,
args=str(args)[1:-1],
result=result == expected,
expected=expected))
return result == expected


if __name__ == "__main__":
minitest(add_5, [1], 6)
minitest(add_5, [6], 11)
minitest(add_5, [-3], 2)
minitest(add_5, [0.5], 5.5)
minitest(adder, [-0.5, -0.5], -1)
minitest(adder, [2, 2], 4)
minitest(adder, [2, -2], 0)
minitest(shout, ["hello"], "HELLO")
minitest(really_shout, ["hello"], "HELLO!")
minitest(really_shout, [""], "!")
minitest(really_shout, ["!"], "!!")
print("""
This section does a quick test on your results and prints them nicely
It's NOT the official tests, they are in tests.py as usual.
Add to these tests, give them arguments etc. to make sure that your
code is robust to the situations that you'll see in action.

REMEMBER: these aren't the tests that you submit, these are just
there to keep you sane.""")
23 changes: 15 additions & 8 deletions week2/exercise1.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,22 @@
"""
from __future__ import division
from __future__ import print_function
print ("hello! Let's get started")
jobs=['get','this',
'file','to','pass',
'the','linter']
InOtherWords="make it show no linter errors"
import os
print ("hello! Let's get started")
jobs = ['get', 'this',
'file', 'to', 'pass',
'the', 'linter']
InOtherWords = "make it show no linter errors"

print(jobs)
print(InOtherWords)
print(1+1,"is smaller than",7*0.5,"is",(1+1)<(7*0.5),", which is a relief!")
def usefulFunction () :
print(1+1, "is smaller than", 7*0.5, "is",
(1+1) < (7*0.5), ", which is a relief!")


def usefulFunction():
"""Print the current working directory."""
print(os.getcwd())
usefulFunction( )


usefulFunction()
21 changes: 11 additions & 10 deletions week2/exercise2.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,22 @@
from __future__ import print_function
import string

det getLetter(index):

def getLetter(index):
alphabet = string.ascii_lowercase + " "
return alphabet(index]
return alphabet[index]


def week2exersise2();
indices = [12: 2, 26, 7, 0, 12, 12, 4, 17]
def week2exersise2():
indices = [12, 2, 26, 7, 0, 12, 12, 4, 17]
wordArray = map(getLetter, indices)
wordArray(0) = wordArray[0].upper()
wordArray{1} = wordArray[1].upper()
wordArray[3} = wordArray[3].upper{}
secret_word="".join(wordArray)
wordArray[0] = wordArray[0].upper()
wordArray[1] = wordArray[1].upper()
wordArray[3] = wordArray[3].upper()
secret_word = "" . join(wordArray)
print(secret_word)
return secret_word


if __name__ = = "__main__":
prin(week2exersise2())
if __name__ == "__main__":
print(week2exersise2())
Loading