Skip to content
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
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"python.linting.pylintEnabled": true,
"python.linting.enabled": true
}
11 changes: 11 additions & 0 deletions Week-2/guess.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import random as r
number = (r.randint(1,10))
print('Choose a number between 1 to 10')
guess = input()
if guess == number:
print('You guessed correct!')
else:
txt = 'You guessed the wrong number, the number was {}'
print(txt.format(number))
#hello

5 changes: 5 additions & 0 deletions Week-2/guess2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import random as r
number = (r.randint(1,10))
print('Choose a number between 1 to 10')
guess = input()
print(guess == number)
5 changes: 5 additions & 0 deletions Week-2/inputtest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
print('What is your name?')
a = input()
print('Your name is {}'.format(a))
b = input('hi say it again, your name is ')
print(b)
12 changes: 12 additions & 0 deletions Week-2/math module.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import math as m
r = 5
area = (5**2) * m.pi
print(area)

x = 3
y = 2 + m.sin(x)
print(y)

z = 5
w = m.log(10,z-3) + (2*(z+4))
print(w)
1 change: 1 addition & 0 deletions Week-2/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print hello
29 changes: 20 additions & 9 deletions Week-3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ We will then start building more complex code and learn how to document it along
2. Set up the git config file on your computer by setting the user name and email address. You can optionally set the other fields, if you want. You will need to only do this once. See the [Github tutorial on setting your username] (https://help.github.com/en/articles/setting-your-username-in-git) and [setting the email address in git](https://help.github.com/en/articles/setting-your-commit-email-address). You can also refer to pg 11 of Pro Git ebook for more details. To set the same username and email address for all git repos, in the terminal type the following:

```
git config --global user.namer "my-user-name"
git config --global user.name "my-user-name"
git config --global user.email "email@example.com"
```

Expand All @@ -24,20 +24,30 @@ git config --global user.email "email@example.com"

![image of fork button](./img/fork-button.png)

2. If you want to, you can set your repo to be private by adjusting the settings of the repo. This means other random internet users won't be able to see your code. On the Github page for you newly forked repository, click on the settings tab.

![image of settings tab](./img/settings-tab.png)
## Cloning a Repository
1. You know need to make a local copy of the repository on your computer so that you can edit the code and add files. You don't want to just download the zip file of the repo as it won't contain the change change recorded by git. Go to your fork of the `dsde1-computing1` repo. You could see the green `Clone or download` button on the left side of window. If you don't you are probably in one of the week folders, go to the top folder.

2. Click on the green `Clone or download` button. Make the sure the option is for SSH not HTTPS. Copy the text displayed. It should start with 'git@github.com:'.

![image of clone button](./img/clone.png)

3. Open a terminal. `cd` to the location on your computer where you would like the code to be located. Type the following into the terminal, replacing the text `paste-here` with the text you copied from Github.

```
git clone paste-here
```

__TIP__: You could also use a version control application to help you clone and manage repositories. [SourceTree](https://www.sourcetreeapp.com/) is one open source option or you use the [Github Desktop application](https://desktop.github.com/).

3. If you want to make the repo private then you can add the lecturer as a collaborator so that only she can see your code. Click on the Collaborators menu on the left of the window. You will be asked enter your password again. You then can add the user theleadingzero as a collaborator.

![image of collaborators menu](./img/collaborators-menu.png)

## Making Your First Commit
1. You will now use your fork of the repo for storing your weekly exercises. Find the Python code you wrote in Week 2 and add it to the `Week-2` folder on your computer.
1. You will now use your fork of the repo for storing your weekly exercises. Find the Python code you wrote in Week 2 and add it to the `Week-2` folder on your computer within the `dsde1-computing1` folders now being tracked in your repository.

2. Commit your added code and push it to the repo. We'll walk through the steps here, but you can also reference the [VS Code documentation](https://code.visualstudio.com/docs/editor/versioncontrol#_commit).

3.Open the file in VS Code. On the left click on the source control button. It will open a new panel in the VS Code interface.
3. Open the file in VS Code. On the left click on the source control button. It will open a new panel in the VS Code interface.

![image of source control button](./img/src-control-button.png)

Expand All @@ -61,8 +71,10 @@ git config --global user.email "email@example.com"

9. Check in the online interface for Github to check that you can now see your code there.



## Using Github for Exercises From Now On
You now have a repo set up in Github and on your computer. You will start using code files that are in the repo in your exercises. You can also save your exercises in this repo and are encouraged to do so. Using git will become easier only with practice.
You now have a repo set up in Github and on your computer. You will start using code files that are in the repo in your exercises. You can also save your exercises in this repo and are encouraged to do so. Using git will become easier only with practice - it's completely normal for it to be frustrating and confusing at first.

Note that you will be expected to use git and Github to fork and commit to repositories in both Assessments.

Expand Down Expand Up @@ -176,4 +188,3 @@ python -m unittest test_pendulum

Correct your code if there are any errors. If the output is that it ran tests and everything is 'OK', then that means your functions passed all the tests. If 'FAILED' is printed instead, then the lines above where it printed 'FAILED' will list what went wrong including what the answer was that your code produced and what the expected answer was.


Binary file added Week-3/__pycache__/pendulum.cpython-37.pyc
Binary file not shown.
Binary file added Week-3/__pycache__/toys.cpython-37.pyc
Binary file not shown.
15 changes: 15 additions & 0 deletions Week-3/counting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
for x in range(11):
print(x)

y = 0
while y < 11:
print(y)
y += 1

for z in range(10,0,-1):
print(z)

w = 0
while w < 11:
print(10-w)
w += 1
9 changes: 9 additions & 0 deletions Week-3/fizzbuzz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
for x in range(1,101):
if x % 15 ==0:
print('FizzBuzz')
elif x % 5 == 0:
print('Buzz')
elif x % 3 ==0:
print('Fizz')
else:
print(x)
21 changes: 21 additions & 0 deletions Week-3/guess.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import random as r
number = (r.randint(1,10))
print('Choose a number between 1 to 10')
i = 0

while i < 3:
x = input('Your guess: ' )
guess = int(x)
if guess > 10 or guess < 1:
print('Please choose a number only between 1 and 10.')
elif guess == number:
print('You guessed correct!')
break
else:
i += 1
wrong = 'You guessed the wrong number. Remaining guesses: {}'
print(wrong.format(3-i))

if i == 3:
txt = 'The number was {}'
print(txt.format(number))
Binary file added Week-3/img/clone.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions Week-3/pendulum.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def period(length , gravity):
import math as m
if isinstance(length, (float, int)) and isinstance(gravity, (float, int)):
if length <= 0 or gravity <=0:
return 'Input positive numbers only.'
else:
return 2*m.pi*((length/gravity)**0.5)
else:
raise(TypeError)

# print(period(7.5,'helo'))

Binary file added Week-3/pendulum.pyc
Binary file not shown.
Binary file added Week-3/test_pendulum.pyc
Binary file not shown.
22 changes: 17 additions & 5 deletions Week-3/test_toys.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@


import unittest
import unittest.mock
import io

import toys as toys

Expand All @@ -14,8 +16,18 @@ def test_inc(self):
'''
Test that it can increment an integer
'''
result = toys.inc_return(10)
self.assertEqual(result, 11)
with unittest.mock.patch('sys.stdout', new=io.StringIO()) as fake_stdout:
toys.inc(10)

result = fake_stdout.getvalue()
self.assertEqual(result, '11\n')

def test_inc_return(self):
'''
Test that it can sum two integers
'''
result = toys.inc_return(9)
self.assertEqual(result, 10)

def test_sum(self):
'''
Expand All @@ -36,14 +48,14 @@ def test_is_odd(self):
Test can detect an odd number
'''
result = toys.is_even(5)
self.assertFalse(result)
self.assertIs(result, False)

def test_is_even(self):
'''
Test can detect an even number
'''
result = toys.is_even(8)
self.assertTrue(result)
self.assertIs(result, True)

def test_string(self):
'''
Expand All @@ -55,4 +67,4 @@ def test_string(self):


if __name__ == '__main__':
unittest.main()
unittest.main()
Binary file added Week-3/test_toys.pyc
Binary file not shown.
28 changes: 18 additions & 10 deletions Week-3/toys.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,42 @@
# write a function that adds 1
# to the input and prints the result
def inc(a):
print(a)

x = a + 1
print(x)

# write a function that adds 1
# to the input and returns the result
def inc_return(a):
return # hint this is incomplete

x = a + 1
return x


# write a function that adds
# the two input numbers together
# and returns the sum
def sum(a, b):
return
z = a + b
return z



# write a function that takes two
# numbers, adds them together using
# sum() and then increments the sum
# using inc_return
def sum_inc(a, b):
return

w = sum(a, b)
return inc_return(w)


# write a function that returns a
# boolean (True or False) for whether
# the input number is even
def is_even(a):
return

if a%2 == 0:
return True
else:
return False

# create for loop that takes a string
# and an integer and returns a new string
Expand All @@ -47,7 +53,9 @@ def is_even(a):
# e.g. string_repeat('ho', 3) returns
# 'hohoho'
def string_repeat(phrase, repeat):
return phrase * repeat
# hint: you can add strings together
# in order to concatenate them
return



Binary file added Week-3/toys.pyc
Binary file not shown.
100 changes: 100 additions & 0 deletions Week-4/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# Week 4 Exercises

# Tuesday - Updating from Github and More on Datatypes

## Updating Your Forked Repo

Changes will be made in the original repo and new files will be added as the weeks progress. You will want to make sure you update your repo with those changes. This is called syncing the fork.

### One-Time Set Up

You only need to do these steps once.

1. Open a terminal and `cd` to your copy of `dsde-computing1`.

2. Type in the following. If both the URLs that are printed are the same, then you need to do the following steps. If the one labelled `(fetch)` is `git@github.com:theleadingzero/dsde1-computing1.git` then you can skip to the next section to update your repo.

```
git remote -v
```

3. You need to tell your repo where to look for updates (the original repo). Do this by typing the following into the terminal.

```
git remote add upstream git@github.com:theleadingzero/dsde1-computing1.git
```

__NOTE__: If you are using https instead of ssh, the you instead want

```
git remote add upstream https://github.com/theleadingzero/dsde1-computing1.git
```

4. Type in the following again. This time it should show an URL with your username for `(push)` and one the `theleadingzero` for `(fetch)`.

```
git remote -v
```

## How to Update Your Repo

Once you've done the above once, the following steps will let you update your repo.

1. Make sure you have any changes to your repo commited and pushed.

6. Type in the following command. This will request any changes from the master repo and save them in a new branch called `upstream`.

```
git fetch upstream
```

7. Now you will request to pull all the changes from the original repo into your branch called `upstream`.

```
git fetch upstream
```

8. You will now switch back to your repo's `master` branch.

```
git checkout master
```

9. You will now merge the changes you fetched with your local repo. If there are any conflicting changes,

```
git merge upstream/master
```


## Manipulating Data Structures

1. Open up `structures.py` and follow the instructions in the comments above each function definition.

2. Run the test file to determine if the function work correctly.

```
python -m unittest test_structures.py
```

## Docstrings

1. Add docstrings to your functions in `structures.py`.

2. Import your module `structures.py` in an interactive Python shell. Check that your docstrings print when calling the `help()` function.

```
import structures as s
help(s.first_and_last)
```

## Linting

1. Run pylint on the file `fuzzy.py` and correct the issues that are printed.

```
pylint fuzzy.py
```

2. Run pylint on your `fuzzy.py` and fix the issues.

Loading