Skip to content

Keeping everyone up to date #1

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 15 commits into
base: master
Choose a base branch
from
Open
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#ignore backupfiles
*.*~
*~

2 changes: 2 additions & 0 deletions Problem_A/another_test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

hi there
17 changes: 17 additions & 0 deletions Problem_B/Problem_B_description.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Problem B
=========

Today's problem is going to be to try to solve the "FizzBuzz" problem.

The rules are:

* You have to count up from 1 up to an integer n (for now, let's say
n = 100).
* If the number you say is divisible by 3, you say "Fizz" instead of the number.
* If the number is divisible by 5, you say "Buzz" instead of the number.
* And if the number is divisible by both 3 & 5, you say "FizzBuzz".

Hint: The % (modulo) operator shows the remainder after a division, and it is pretty useful in this case.
It can help you work out if something is divisible by another number (if the remainder is zero)

Save your answer in a file in the 'Problem_B' folder
Empty file added Problem_B/solu.py
Empty file.
9 changes: 9 additions & 0 deletions Problem_C/Problem_C.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Problem C
---------

Today's problem will be entirely git based, just to get everyone who may have missed a session or two back up to speed.

The task is to make a file in the folder, and then share that change with your partner.
They must then make a change in the file and share the change back, both using pull requests in Github.

Make sure you use Chrome or Chromium, as our old version of Firefox is not supported by GitHub!
23 changes: 23 additions & 0 deletions Problem_D/Problem_D.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Problem D
---------

Today's problem will have a little bit of coding in it, since we're slowly starting to get the hang of git.

The problem is a nice simple one:

Write a function that takes in a number and computes the factorial of that number.
The factorial (!) is the multiplication of all the numbers from one from that number, so:

```
1! = 1 = 1
2! = 1*2 = 2
3! = 1*2*3 = 6
4! = 1*2*3*4 = 24
5! = 1*2*3*4*5 = 120
```
Save your solution in Problem_D folder!

We will be doing the same pull-request as with previous tasks to share the change with your partner.

Make sure you use Chrome or Chromium, as our old version of Firefox is not supported by GitHub!

35 changes: 35 additions & 0 deletions Problem_D/python_factorial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
def fact1(n): #iterative
answer = 1
if n < 0:
raise Exception("Cannot take factorial of a negative")
else:
for i in range(1,n+1):
answer = answer*i
return answer


def fact2(n): #recursive
if n < 0:
raise Exception("Cannot take factorial of a negative")
if n == 0:
return 1
else:
return n*fact2(n-1)

#tests!
print fact1(0)
print fact1(1)
print fact1(2)
print fact1(3)
print fact1(4)
print fact1(5)
print fact2(0)
print fact2(1)
print fact2(2)
print fact2(3)
print fact2(4)
print fact2(5)

#these will throw exceptions
print fact2(-1)
print fact1(-1)
37 changes: 37 additions & 0 deletions Problem_E/Problem_E.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Problem E
---------

Today we're going to write an interactive game!

Rock Paper Scissors is a nice game to play with a computer as the rules are fairly straightforward.

The task is to write a program that will run a tournament of Rock-Paper-Scissors.

The program should take input from the console, corresponding to your move, and then print out its *random* move.
It should then work out who won or if it was a draw, and print out a message saying who won.
We want to be able to play more than one round at a time, so you will need a loop so that you can run several rounds after each other.

Note: This is a slightly bigger project than what we normally do, so we will split it over two weeks. I have separated out which part I would focus on for which week, but you are welcome to change it around! If you finish with Part 1 early, feel free to move on to Part 2.


### Part 1: Week 1

You will need a program that runs in a loop, that will take in a value for your move.
It should check if it is one of the allowed values ('r', 'p', 's', 'R', 'P', 'S') and print "this is a legal move".
If it is not a legal move, it should end the tournament (break out of the loop) and print "tournament over" before quitting.

### Part 2: Week 2

You will now need to get the computer to generate a random move after you type in your value. There are random functions in Python and MATLAB which will make this easier.

Lastly, you will need to get the computer to compare your move to its move, and work out if it's a "COMPUTER WINS", or "YOU WIN" or "DRAW".
This will replace the line that said "this is a legal move".

Play your game!

### Part 3: On your own time

You could keep a running count of how many times you or the computer won and at the end of the game, print out the tournament winner.

If you're a fan of The Big Bang Theory, you might want to extend your program to play Rock-Paper-Scissors-Lizard-Spock (RPSLK)

53 changes: 53 additions & 0 deletions Problem_E/Sample_E_Solution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import random

def main():
#keep track of the final scores
totalcomputerwins = 0
totalplayerwins = 0

while (True):
playermove = raw_input("Make your move: ")
if playermove not in ['r','p','s','R','P','S']:
#they want out of the tournament:
break;
#now we're sure we have a legit move
#print "this is a legal move"

#get rid of case sensitivity:
playermove = playermove.upper() #make it uppercase.
computermove = random.choice(['R','P','S']) #makes a random choice.
print "Computer moved: {}".format(computermove)
#implement the rules:
#if they are the same, it's a draw:
if playermove == computermove:
print "Draw"
continue #we're done with this round, go to the next one.
#cases where the player wins:
elif (playermove == 'S' and computermove == 'P') or \
(playermove == 'P' and computermove == 'R') or \
(playermove == 'R' and computermove == 'S'):
print "You Win"
totalplayerwins += 1
else: #player must have lost
print "Computer Win"
totalcomputerwins += 1




#print "tournament over"
#Print out the final scores.
print "PLAYER: {}, COMPUTER: {}".format(totalplayerwins, totalcomputerwins)
if totalcomputerwins == totalplayerwins:
print "TOURNAMENT RESULTS: DRAW!"
elif totalcomputerwins > totalplayerwins:
print "TOURNAMENT RESULTS: COMPUTER WINS!"
else:
print "TOURNAMENT RESULTS: YOU WIN!"




if __name__ == "__main__":
main()

Empty file added test.txt
Empty file.
49 changes: 49 additions & 0 deletions using_git.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Using Git for The Pair Programming Club
## Laura (starrymirth)

Git is a really great version control tool, it's very powerful and flexible, but
that does mean that sometimes it can be a little bit confusing to the beginner.
There are great tutorials online (including the book http://git-scm.com/book),
but this will be a reference document for the git commands that we will use most often.

### Setting up an account on GitHub:

Pop over to (https://github.com) and make an account (username, email and password).
Note that it will be public, and all projects will be public. If you need to work on something for work, there is an internal GitLab server (talk to HT for more information) or if you're working on your own private stuff I recommend Bitbucket, which allows you to have Private projects for very small groups.

Once you have an account head over to the pair programming repository on my account
(https://github.com/starrymirth/PairProgramming), and click the `Fork` button in the top right hand corner. This will take you to your own 'copy' of the repository, which you can edit freely.

**NOTE:** There seems to be a bit of an issue with Firefox cache on Linux machines which prevents the Fork from working correctly. If you get to a page that asks you which repository to fork to, and it doesn't let you click the button, either try using Chrome, or clear Firefox's cache by going to `Menu>Preferences>Advanced>Network` and clicking the `Clear Now` button under `Cached Web Content`.

### Common Commands

#### `git clone`
When you first want to get the code from GitHub you need to use `git clone`. If you're working on the lab machines we will use HTTPS, so on the page from GitHub at the bottom right you will see a "HTTPS clone URL" (if it says SSH click the HTTPS button).

You can then run from the terminal the command and that URL, which will be in the form:

`git clone https://github.com/<username>/<repository_name>.git`

That will create a folder the same name as the repository into the folder you are in.


#### `git status`
Use this command all the time when you want to see what's going on. It will tell you what is changed, what is staged, and what is pushed to the server.

#### `git pull`
If there have been other changes to the repository that were not on your computer but are on the server, you need to `pull` them from the server, with `git pull`. The default is to pull from your origin, which is the GitHub server, so you don't need to tell it where to pull from.

#### `git add`
When you add or modify a file, you need to add to to the staging area, (basically tell git that you care about that file and you want the changes to happen when you commit). Use `git add <filename>`

#### `git commit`
This will make a package of all your changes, and you need to give a message basically summarising what you changed. If you say `git commit`, it will open a editor to write your message, but you can do it easier by just typing `git commit -m "<your message here>"`


#### `git push`
This does the opposite of pull, which is to push your changes to the server. If someone has been editing the server, it will prevent you from doing this. You can simply run `git push`, but if your machine is not configured correctly it may give a warning. That is ok, but if you want to get into the habit you can run `git push origin master` which is explicit, saying that we want to push to the `origin` and we want to push the `master` branch. We will not go into branching at this point, so this will always be the same.