Skip to content
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

Alex Botello #4

Open
wants to merge 70 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
c7e3c63
Complete args.py
Jul 31, 2018
02f50cc
Complete bignum.py
Jul 31, 2018
3bd1c2b
Complete comp.py
Jul 31, 2018
2077a7c
Complete hello
Jul 31, 2018
b334e36
Complete datatypes
Jul 31, 2018
79e27ec
Complete dicts
Jul 31, 2018
45fa33d
Complete fileio
Jul 31, 2018
a74007e
Complete func.py
Jul 31, 2018
c0f545f
Complete lists.py
Jul 31, 2018
236ff04
Complete modules.py
Jul 31, 2018
74f3264
Complete obj.py
Jul 31, 2018
2490097
Complete printf.py
Jul 31, 2018
bfa4f6c
scope.py
Jul 31, 2018
85c4b85
Complete slice.py
Jul 31, 2018
41a713f
Complete tuples.py
Jul 31, 2018
3f7d8ae
Complete cal.py
Jul 31, 2018
70b6982
Complete adv
Aug 1, 2018
4a6ceec
Add item class
Aug 4, 2018
dec6926
Add game class
Aug 4, 2018
445a95b
Allow player to carry items
Aug 4, 2018
3654893
Allow room to contain items
Aug 4, 2018
3e3f3f3
import the random module
Aug 4, 2018
97acc37
Bug fix: properly read words text file
Aug 4, 2018
8e8c3af
Convert strikes into a string when printing
Aug 4, 2018
31b33ec
Random number generator's range should be no greater than length of w…
Aug 4, 2018
a5c4870
Fix typo in greeting
Aug 4, 2018
02f0db9
Correctly add all alpha characters into alphabet list
Aug 4, 2018
4b4670b
Initialize curWord to be global variable
Aug 4, 2018
3bc128e
Remove all camelcase and convert to snake case
Aug 4, 2018
31fc2aa
More snake_case changes
Aug 4, 2018
2b28b3a
Fix off by one error in fill_letters function
Aug 4, 2018
0861741
Print actual letters left each turn
Aug 4, 2018
470818c
Fix bug where winning displays the correct message
Aug 4, 2018
329241a
Seperate game class and add text colors
Aug 6, 2018
423a6ce
Rename some attributes in Player class
Aug 6, 2018
c4b3c1f
Make the name a private attribute
Aug 6, 2018
af3e38c
Add color to room string representation
Aug 6, 2018
dcf6127
Dynamically add new rooms by reading file
Aug 6, 2018
0455d5a
Create rooms file for reading list of rooms
Aug 6, 2018
54e7c24
Invalid input will now appear as magenta
Aug 6, 2018
112649c
Refactor function name for main loop
Aug 6, 2018
97b230e
Encapsulate room setup inside generate_all_rooms function
Aug 6, 2018
2ca8746
Rearrange methods for class Game
Aug 6, 2018
b038403
Add items into rooms
Aug 7, 2018
a3c0ac1
Add take and drop methods
Aug 7, 2018
c672893
Modify items setter
Aug 7, 2018
2cc18a0
Refactor take and drop methods with try/except
Aug 7, 2018
dcf5505
Add action input functionality to Game class
Aug 7, 2018
17c9848
Add name property for Player
Aug 7, 2018
0684ef1
Rename dir dict to have a better name
Aug 7, 2018
f98938a
Add inventory command
Aug 7, 2018
6609240
Handle keyboardinterrupt exception when game closes
Aug 7, 2018
b9bcad0
Add _greeting function
Aug 7, 2018
a622329
Create generate_items function to randomly add items into rooms
Aug 8, 2018
f252d8f
Modify generate_items to exhaust all items
Aug 8, 2018
dd6a590
Remove debugging print statement
Aug 8, 2018
b034466
Refactor call method and add else condition for wrong direction
Aug 8, 2018
7c20323
Refactor items to set one item at a time
Aug 8, 2018
cad3a80
generate_map function now handles room linking
Aug 8, 2018
48e15ba
Refactor take and drop methods to utilize Item class
Aug 8, 2018
0297f0a
Call setup functions inside generate_rooms
Aug 8, 2018
8ca26d3
Clean up some names to be more descriptive
Aug 9, 2018
b7ccd14
Create functions for color printing
Aug 9, 2018
9032e80
Add Treasure class that inherits from Item
Aug 9, 2018
c87b8b6
Refactor self.directions to self.attributes
Aug 9, 2018
7d10443
Refactor some names to make more descriptive
Aug 9, 2018
3887f37
Move start_game function to beginning of file
Aug 10, 2018
35eec4d
Add score command and display players score
Aug 10, 2018
c5159ba
Game now generates treasure
Aug 10, 2018
cfba813
Picking up treasure now raises a players score
Aug 10, 2018
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
22 changes: 17 additions & 5 deletions src/day-1-toy/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@
# Write a function f1 that takes two integer positional arguments and returns
# the sum. This is what you'd consider to be a regular, normal function.

#def f1(...
def f1(num, num2):
return num + num2

print(f1(1, 2))

# Write a function f2 that takes any number of iteger arguments and prints the
# sum. Google for "python arbitrary arguments" and look for "*args"

# def f2(...
def f2(*args, **kwargs):
sum = 0
for num in args:
sum += num
return sum

print(f2(1)) # Should print 1
print(f2(1, 3)) # Should print 4
Expand All @@ -21,13 +27,16 @@
a = [7, 6, 5, 4]

# What thing do you have to add to make this work?
print(f2(a)) # Should print 22
print(f2(*a)) # Should print 22

# Write a function f3 that accepts either one or two arguments. If one argument,
# it returns that value plus 1. If two arguments, it returns the sum of the
# arguments. Google "python default arguments" for a hint.

#def f3(...
def f3(arg, arg2=None):
if arg2 is None:
return arg + 1
return arg + arg2

print(f3(1, 2)) # Should print 3
print(f3(8)) # Should print 9
Expand All @@ -41,7 +50,10 @@
#
# Google "python keyword arguments".

#def f4(...
def f4(*args, **kwargs):
for key, val in kwargs.items():
print(f"Key: {key}, Value: {val}")


# Should print
# key: a, value: 12
Expand All @@ -60,4 +72,4 @@
}

# What thing do you have to add to make this work?
f4(d)
f4(**d)
3 changes: 3 additions & 0 deletions src/day-1-toy/bar.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Hello
This is easy
I am ready for Django
3 changes: 2 additions & 1 deletion src/day-1-toy/bignum.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# Print out 2 to the 65536 power
# Print out 2 to the 65536 power
print(2**65536)
6 changes: 6 additions & 0 deletions src/day-1-toy/cal.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@
# docs for the calendar module closely.

import sys
import calendar
import datetime

year, month = int(sys.argv[1]), int(sys.argv[2])
print(calendar.monthcalendar(year, month))

10 changes: 5 additions & 5 deletions src/day-1-toy/comp.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Write a list comprehension to produce the array [1, 2, 3, 4, 5]

y = []
y = [x for x in range(1, 6)]

print (y)
print(y)

# Write a list comprehension to produce the cubes of the numbers 0-9:
# [0, 1, 8, 27, 64, 125, 216, 343, 512, 729]

y = []
y = [x**3 for x in range(10)]

print(y)

Expand All @@ -16,7 +16,7 @@

a = ["foo", "bar", "baz"]

y = []
y = [x.upper() for x in a]

print(y)

Expand All @@ -26,7 +26,7 @@
x = input("Enter comma-separated numbers: ").split(',')

# What do you need between the square brackets to make it work?
y = []
y = [num for num in x if int(num) % 2 == 0]

print(y)

4 changes: 2 additions & 2 deletions src/day-1-toy/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
y = "7"

# Write a print statement that combines x + y into the integer value 12
print(x + y)
print(x + int(y))

# Write a print statement that combines x + y into the string value 57
print(x + y)
print(str(x) + y)
10 changes: 8 additions & 2 deletions src/day-1-toy/dicts.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
"lat": 43,
"lon": -121,
"name": "a place"
},
},
{
"lat": 41,
"lon": -123,
"name": "another place"
},
},
{
"lat": 43,
"lon": -122,
Expand All @@ -25,5 +25,11 @@
]

# Write a loop that prints out all the field values for all the waypoints
for point in waypoints:
print(point.items())

# Add a new waypoint to the list
waypoints.append({"lat": 41, "lon": 20, "name": "a fourth place"})

for point in waypoints:
print(point.items())
9 changes: 7 additions & 2 deletions src/day-1-toy/fileio.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@
# Print all the lines in the file

# Close the file

with open('foo.txt', 'r') as f:
for line in f.readlines():
print(line)

# Use open to open file "bar.txt" for writing

# Use the write() method to write three lines to the file

# Close the file
# Close the file
with open('bar.txt', 'w') as f:
f.write('Hello\nThis is easy\nI am ready for Django')

9 changes: 7 additions & 2 deletions src/day-1-toy/func.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Write a function is_even that will return true if the passed in number is even.

def is_even(num):
return int(num) % 2 == 0
# Read a number from the keyboard
num = input("Enter a number: ")

# Print out "Even!" if the number is even. Otherwise print "Odd"
# Print out "Even!" if the number is even. Otherwise print "Odd"
if is_even(num):
print('Even!')
else:
print('Odd')
3 changes: 2 additions & 1 deletion src/day-1-toy/hello.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# Write Hello, world
# Write Hello, world
print("Hello, world")
13 changes: 7 additions & 6 deletions src/day-1-toy/lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,24 @@
# For the following, DO NOT USE AN ASSIGNMENT (=).

# Change x so that it is [1, 2, 3, 4]
# [command here]
x.append(4)
print(x)

# Using y, change x so that it is [1, 2, 3, 4, 8, 9, 10]
# [command here]
x+=y
print(x)

# Change x so that it is [1, 2, 3, 4, 9, 10]
# [command here]
x.remove(8)
print(x)

# Change x so that it is [1, 2, 3, 4, 9, 99, 10]
# [command here]
x.insert(5, 99)
print(x)

# Print the length of list x
# [command here]
print(len(x))

# Using a for loop, print all the element values multiplied by 1000
# Using a for loop, print all the element values multiplied by 1000
for num in x:
print(num*1000)
11 changes: 6 additions & 5 deletions src/day-1-toy/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
# See docs for the sys module: https://docs.python.org/3.7/library/sys.html

# Print out the command line arguments in sys.argv, one per line:
print(sys.argv[1:])


# Print out the plaform from sys:
print()
print(sys.platform)

# Print out the Python version from sys:
print()
print(sys.version)



Expand All @@ -21,11 +22,11 @@
# See the docs for the OS module: https://docs.python.org/3.7/library/os.html

# Print the current process ID
print()
print(os.getpid())

# Print the current working directory (cwd):
print()
print(os.getcwd())

# Print your login name
print()
print(os.getlogin())

29 changes: 25 additions & 4 deletions src/day-1-toy/obj.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,42 @@
# Make a class LatLon that can be passed parameters `lat` and `lon` to the
# constructor

class LatLon:
def __init__(self, lat, lon):
self.lat = lat
self.lon = lon
# Make a class Waypoint that can be passed parameters `name`, `lat`, and `lon` to the
# constructor. It should inherit from LatLon.
class Waypoint(LatLon):
def __init__(self, name, lat, lon):
super().__init__(lat, lon)
self.name = name

def __repr__(self):
return f"Waypoint: {self.name}, {self.lat}, {self.lon}"


# Make a class Geocache that can be passed parameters `name`, `difficulty`,
# `size`, `lat`, and `lon` to the constructor. What should it inherit from?
class Geocache(Waypoint):
def __init__(self, name, difficulty, size, lat, lon):
super().__init__(name, lat, lon)
self.difficulty = difficulty
self.size = size

def __repr__(self):
return f'Geocache: {self.name}, diff {self.difficulty}, size {self.size}, {self.lat}, {self.lon}'


# Make a new waypoint "Catacombs", 41.70505, -121.51521
cata = Waypoint('Catacombs', 41.70505, -121.51521)

# Print it
#
print(cata)
# Without changing the following line, how can you make it print into something
# more human-readable?
print(w)

# Make a new geocache "Newberry Views", diff 1.5, size 2, 44.052137, -121.41556
geo = Geocache('Newberry Views', 1.5, 2, 44.052137, -121.41556)

# Print it--also make this print more nicely
print(g)
print(geo)
4 changes: 3 additions & 1 deletion src/day-1-toy/printf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
# Using the printf operator (%), print the following feeding in the values of x,
# y, and z:
# x is 10, y is 2.25, z is "I like turtles!"
print(f"x is {x}, y is {y}, z is {z}")


# Use the 'format' string method to print the same thing
# Use the 'format' string method to print the same thing
print("x is {}, y is {}, z is {}".format(x, y, z))
2 changes: 2 additions & 0 deletions src/day-1-toy/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
x = 12

def changeX():
global x
x = 99

changeX()
Expand All @@ -19,6 +20,7 @@ def outer():
y = 120

def inner():
nonlocal y
y = 999

inner()
Expand Down
14 changes: 7 additions & 7 deletions src/day-1-toy/slice.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
a = [2, 4, 1, 7, 9, 6]

# Output the second element: 4:
print()
print(a[1])

# Output the second-to-last element: 9
print()
print(a[4])

# Output the last three elements in the array: [7, 9, 6]
print()
print(a[3:])

# Output the two middle elements in the array: [1, 7]
print()
print(a[2:4])

# Output every element except the first one: [4, 1, 7, 9, 6]
print()
print(a[1:])

# Output every element except the last one: [2, 4, 1, 7, 9]
print()
print(a[:5])

# For string s...

s = "Hello, world!"

# Output just the 8th-12th characters: "world"
print()
print(s[7:])
8 changes: 5 additions & 3 deletions src/day-1-toy/tuples.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def dist(a, b):
"""Compute the distance between two x,y points."""
x0, y0 = a # Destructuring assignment
x1, y1 = b

return math.sqrt((x1 - x0)**2 + (y1 - y0)**2)

a = (2, 7) # <-- x,y coordinates stored in tuples
Expand All @@ -22,11 +22,13 @@ def dist(a, b):

# Write a function that prints all the values in a tuple

# def print_tuple(...
def print_tuple(tuple):
for t in tuple:
print(t)

t = (1, 2, 5, 7, 99)
print_tuple(t) # Prints 1 2 5 7 99, one per line

# Declare a tuple of 1 element then print it
u = (1) # What needs to be added to make this work?
u = (1,) # What needs to be added to make this work?
print_tuple(u)
Loading