Skip to content

Commit 5aefc2b

Browse files
authored
Merge branch 'main' into kacey-lab10-atm
2 parents 7cfe01e + 3fc40bd commit 5aefc2b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+2884
-36
lines changed

0 General/11 Git Lab Workflow.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
`git status`
2727

2828
1. Use whichever or these four options is appropriate to add the necessary files to git tracking:
29-
`git add .`
30-
`git add <filepath>`
31-
`git add <directorypath>`
32-
`git add -A`
29+
`git add .` # Add file changes in current directory and below to staging.
30+
`git add <filepath>` # Add a specific filepath to staging.
31+
`git add <directorypath>` # Add a specific directory path to staging.
32+
`git add -A` # Add all file changes in whole repository to staging.
3333

3434
1. Use `git status` to view what files and directories will be added to the commit:
3535
`git status`
@@ -71,7 +71,11 @@
7171
## Switch between in-progress branches.
7272

7373
1. Git `add` and `commit` changes to current branch:
74-
1. `git add -A`
74+
1. Use whichever `git add` option as appropriate:
75+
* `git add .`
76+
* `git add <filepath>`
77+
* `git add <directorypath>`
78+
* `git add -A`
7579
1. `git commit -m <commit message>`
7680

7781
1. Checkout the different branch we want to work on:
@@ -80,7 +84,11 @@
8084
1. Do the code changes for this branch.
8185

8286
1. Git `add` and `commit` changes to the new current branch `<a-branch-name>`:
83-
1. `git add -A`
87+
1. Use whichever `git add` option as appropriate:
88+
* `git add .`
89+
* `git add <filepath>`
90+
* `git add <directorypath>`
91+
* `git add -A`
8492
1. `git commit -m <commit message>`
8593

8694
1. Checkout some other branch we want to work on:
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
class Reader:
2+
3+
def __init__(self, book_file):
4+
self.book_file = book_file
5+
self.text = ''
6+
7+
def load(self):
8+
"""
9+
1) open 'file' with option 'r' for read
10+
2) get the text from the file
11+
"""
12+
with open(self.book_file, "r") as f_read:
13+
self.text = f_read.read()
14+
15+
return self.text
16+
17+
def edit(self, new_text):
18+
"""
19+
1) open file with open 'w' for write
20+
2) take in additional text & concat onto existing file
21+
3) save to the file
22+
"""
23+
with open(self.book_file, "a") as f_write:
24+
f_write.write(new_text)
25+
26+
def replace(self, new_text):
27+
with open(self.book_file, "w") as f_write:
28+
f_write.write(new_text)
29+
30+
def print(self):
31+
"""
32+
print the text
33+
"""
34+
35+
36+
def main():
37+
text = Reader('/Users/sb/Desktop/class_HB2/1 Python/docs/class_code_examples/fileIO/book.txt') # create an instance of our class
38+
text.load()
39+
while True:
40+
command = input('Enter a command: ')
41+
if command == 'save':
42+
new_text = input('add new text: ')
43+
text.save(new_text)
44+
elif command == 'print':
45+
print('heeey')
46+
else:
47+
print('Command not recognized')
48+
49+
50+
if __name__ == "__main__":
51+
main()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
David 5551234
2+
Alice 6662345
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
name,phone number,state,zipe code
2+
Sarah Beth,123432112,VA,22906
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import pylyrics3
2+
# https://github.com/jameswenzel/pylyrics3
3+
4+
5+
bon_iver_lyrics = pylyrics3.get_artist_lyrics('bon iver')
6+
7+
print(bon_iver_lyrics)
8+
9+
10+
while True:
11+
artist = input('What artist do you want to look up?')
12+
print(pylyrics3.get_artist_lyrics(artist))

1 Python/labs/11 Contact List.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
# Lab 11: Contact List
3+
4+
5+
Let's build a program to manage a list of contacts. To start, we'll build a CSV ('comma separated values') together, and go over how to load that file. Headers might consist of `name`, `favorite fruit`, `favorite color`. Open the CSV, convert the lines of text into a **list of dictionaries**, one dictionary for each user. The text in the header represents the **keys**, the text in the other lines represent the **values**.
6+
7+
```python
8+
with open('contacts.csv', 'r') as file:
9+
lines = file.read().split('\n')
10+
print(lines)
11+
```
12+
13+
Once you've processed the file, your list of contacts will look something like this...
14+
```python
15+
contacts = [
16+
{'name':'matthew', 'favorite fruit':'blackberries', 'favorite color':'orange'},
17+
{'name':'sam', 'favorite fruit':'pineapple' ...}
18+
]
19+
```
20+
21+
*Note: There is a `csv` library in Python that will do much of this for you. It is what you would use normally in a project, but for this lab you need to write all the logic yourself.*
22+
23+
## Version 2
24+
25+
Implement a CRUD REPL
26+
27+
- **C**reate a record: ask the user for each attribute, add a new contact to your contact list with the attributes that the user entered.
28+
- **R**etrieve a record: ask the user for the contact's name, find the user with the given name, and display their information
29+
- **U**pdate a record: ask the user for the contact's name, then for which attribute of the user they'd like to update and the value of the attribute they'd like to set.
30+
- **D**elete a record: ask the user for the contact's name, remove the contact with the given name from the contact list.
31+
32+
## Version 3
33+
34+
When REPL loop finishes, write the updated contact info to the CSV file to be saved. I highly recommend saving a backup `contacts.csv` because you likely won't write it correctly the first time.
35+

1 Python/labs/Connect Four Mob.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
Connect Four
2+
3+
[Connect Four](https://en.wikipedia.org/wiki/Connect_Four) is a board game.
4+
Players take turns placing tokens of their color into a vertical grid.
5+
They drop to the bottom, and if anyone has four of their color in a straight line, they've won!
6+
7+
Define a module that simulates a Connect Four game.
8+
9+
This will consist of the following classes:
10+
11+
`Player`:
12+
- Properties
13+
- `name`
14+
- `color`
15+
16+
`Game`:
17+
- Properties
18+
- `board`: 7x6 board representation
19+
20+
- Methods
21+
- `get_height(position)`: returns int of how many pieces occupy a column
22+
- `move(player, position)`: adds a player token to a column after figuring out the current height of the column
23+
- `calc_winner()`: returns true if a match (four in a row) is found
24+
- `is_full()`: returns true if all board positions are occupied
25+
- `is_game_over()`: returns true if the game is over (a winner is found or the board is full)
26+
27+
28+
Create a program that simulates the _just playing moves_ of an existing Connect Four game.
29+
Do not concern yourself with figuring out who has won.
30+
31+
It will read a file that contains a history of the moves in a game.
32+
Assume the playing board is made of columns numbered 1 through 7.
33+
The file will have one line for each move (players alternate).
34+
The number in that line is the column the current player placed a token in.
35+
36+
Use the following [example move file](./connect_four/connect-four-moves.txt).
37+
Save it in something like `connect-four-moves.txt`
38+
This moves file recreates [this game](https://en.wikipedia.org/wiki/File:Connect_Four.gif).
39+
40+
* Think about how to figure out how far that token will fall in a given column.
41+
42+
* Think about how to place a token in a column.
43+
44+
* Think about how to concisely store the tokens that have been dropped in the board.
45+
46+
* Read in moves from the file.
47+
48+
* After each move, print out a representation of the board.
49+
You can use `R` and `Y` to represent the pieces.
50+
51+
## Version 2
52+
53+
* Once all moves are done, also print out what player, if any, won.
54+
55+
## Version 3
56+
57+
* Make game playable
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
4
2+
3
3+
5
4+
6
5+
4
6+
4
7+
5
8+
3
9+
6
10+
2
11+
7
12+
7
13+
3
14+
7
15+
4
16+
5
17+
6
18+
5

1 Python/labs/game_start.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
class Player:
2+
'''
3+
' A class to represent each player
4+
' Attributes: name and color
5+
'''
6+
7+
class Game:
8+
'''
9+
' A connect four game object.
10+
' Attributes: game board (7x6 2D nested list)
11+
' Methods:
12+
' get_height(position) returns int of how many pieces occupy a column
13+
' move(player,position) adds a player token to a column after figuring out the current height of the column
14+
' calc_winner(): returns True if four in a row are found
15+
' is_full(): returns true if all board positions are occupied
16+
' is_game_over(): returns true if the game is over (a winnder is found or the board is full)
17+
' play_turn(): function that plays one turn
18+
' play(): function that plays whole game, given two player
19+
' recursive_chip_checker(): recurisvely checks in all directions to find if theres a connect 4
20+
'''
21+
22+
if __name__ == '__main__':
23+
# if this module is run directly, this code will run
24+
# if the module is imported into another, it won't run
25+
26+
game = Game()
27+
with open('1 Python/docs/class_code_examples/connect-four-moves.txt', 'r') as moves:
28+
29+
for move_num, line in enumerate(moves):
30+
print(line)
31+
col_to_play = int(line.strip()) - 1
32+
player = 'Y' if move_num % 2 != 0 else 'R'
33+
game.play_turn(player, col_to_play)
34+
# OPTIONAL/BONUS: print board after each turn
35+
game.is_game_over() # could be called w/in play_turn, or in a different order
36+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
# Lab: LCR Simulator
3+
4+
LCR is a dice game, one of pure chance. Therefore, we can write a simulator to avoid wasting the time playing it ourselves. Description from [wikipedia](https://en.wikipedia.org/wiki/LCR_(dice_game)):
5+
6+
7+
> Each player receives at least 3 chips. Players take it in turn to roll three six-sided dice, each of which is marked with "L", "C", "R" on one side, and a single dot on the three remaining sides. For each "L" or "R" thrown, the player must pass one chip to the player to his left or right, respectively. A "C" indicates a chip to the center (pot). A dot has no effect.
8+
9+
>If a player has fewer than three chips left, he/she is still in the game but his number of chips is the number of dice he/she rolls on his/her turn, rather than rolling all three. When a player has zero chips, he/she passes the dice on his turn, but may receive chips from others and take his next turn accordingly. The winner is the last player with chips left. He/she does not roll the dice, and wins the center pot. If he/she chooses to play another round, he/she does not roll 3, he/she keeps his pot and plays with that.
10+
11+
12+
When the program starts, it should ask for the names of the players, until the user enters 'done'. Then it should run the simulation, tell the user who won, and ask the player whether they'd like to play again.

0 commit comments

Comments
 (0)