From 266f14d8dd091701750db7150a30b4c9471b3099 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 31 Jul 2018 00:03:41 -0400 Subject: [PATCH 01/10] up to lists.py completed --- Pipfile | 1 + Pipfile.lock | 91 +++++++++++++++++++++++++++++++++++++- src/day-1-toy/bignum.py | 3 +- src/day-1-toy/datatypes.py | 4 +- src/day-1-toy/hello.py | 3 +- src/day-1-toy/lists.py | 13 +++--- src/day-1-toy/modules.py | 13 +++--- src/day-1-toy/printf.py | 4 +- 8 files changed, 111 insertions(+), 21 deletions(-) diff --git a/Pipfile b/Pipfile index 3e601a5316..8698f323e1 100644 --- a/Pipfile +++ b/Pipfile @@ -6,6 +6,7 @@ name = "pypi" [packages] [dev-packages] +pylint = "*" [requires] python_version = "3" diff --git a/Pipfile.lock b/Pipfile.lock index a36a2c8975..a378be1b9c 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "4e61a4ba9e6f02f50f68627253af5ababd9b1b4c1e10294e48158e1f42c0c5a6" + "sha256": "8159f2897c60bb49d8c3dba897a90e1c7946f529f7c725987f3a3bea8156abdc" }, "pipfile-spec": 6, "requires": { @@ -16,5 +16,92 @@ ] }, "default": {}, - "develop": {} + "develop": { + "astroid": { + "hashes": [ + "sha256:0a0c484279a5f08c9bcedd6fa9b42e378866a7dcc695206b92d59dc9f2d9760d", + "sha256:218e36cf8d98a42f16214e8670819ce307fa707d1dcf7f9af84c7aede1febc7f" + ], + "version": "==2.0.1" + }, + "colorama": { + "hashes": [ + "sha256:463f8483208e921368c9f306094eb6f725c6ca42b0f97e313cb5d5512459feda", + "sha256:48eb22f4f8461b1df5734a074b57042430fb06e1d61bd1e11b078c0fe6d7a1f1" + ], + "markers": "sys_platform == 'win32'", + "version": "==0.3.9" + }, + "isort": { + "hashes": [ + "sha256:1153601da39a25b14ddc54955dbbacbb6b2d19135386699e2ad58517953b34af", + "sha256:b9c40e9750f3d77e6e4d441d8b0266cf555e7cdabdcff33c4fd06366ca761ef8", + "sha256:ec9ef8f4a9bc6f71eec99e1806bfa2de401650d996c59330782b89a5555c1497" + ], + "markers": "python_version != '3.3.*' and python_version >= '2.7' and python_version != '3.2.*' and python_version != '3.0.*' and python_version != '3.1.*'", + "version": "==4.3.4" + }, + "lazy-object-proxy": { + "hashes": [ + "sha256:0ce34342b419bd8f018e6666bfef729aec3edf62345a53b537a4dcc115746a33", + "sha256:1b668120716eb7ee21d8a38815e5eb3bb8211117d9a90b0f8e21722c0758cc39", + "sha256:209615b0fe4624d79e50220ce3310ca1a9445fd8e6d3572a896e7f9146bbf019", + "sha256:27bf62cb2b1a2068d443ff7097ee33393f8483b570b475db8ebf7e1cba64f088", + "sha256:27ea6fd1c02dcc78172a82fc37fcc0992a94e4cecf53cb6d73f11749825bd98b", + "sha256:2c1b21b44ac9beb0fc848d3993924147ba45c4ebc24be19825e57aabbe74a99e", + "sha256:2df72ab12046a3496a92476020a1a0abf78b2a7db9ff4dc2036b8dd980203ae6", + "sha256:320ffd3de9699d3892048baee45ebfbbf9388a7d65d832d7e580243ade426d2b", + "sha256:50e3b9a464d5d08cc5227413db0d1c4707b6172e4d4d915c1c70e4de0bbff1f5", + "sha256:5276db7ff62bb7b52f77f1f51ed58850e315154249aceb42e7f4c611f0f847ff", + "sha256:61a6cf00dcb1a7f0c773ed4acc509cb636af2d6337a08f362413c76b2b47a8dd", + "sha256:6ae6c4cb59f199d8827c5a07546b2ab7e85d262acaccaacd49b62f53f7c456f7", + "sha256:7661d401d60d8bf15bb5da39e4dd72f5d764c5aff5a86ef52a042506e3e970ff", + "sha256:7bd527f36a605c914efca5d3d014170b2cb184723e423d26b1fb2fd9108e264d", + "sha256:7cb54db3535c8686ea12e9535eb087d32421184eacc6939ef15ef50f83a5e7e2", + "sha256:7f3a2d740291f7f2c111d86a1c4851b70fb000a6c8883a59660d95ad57b9df35", + "sha256:81304b7d8e9c824d058087dcb89144842c8e0dea6d281c031f59f0acf66963d4", + "sha256:933947e8b4fbe617a51528b09851685138b49d511af0b6c0da2539115d6d4514", + "sha256:94223d7f060301b3a8c09c9b3bc3294b56b2188e7d8179c762a1cda72c979252", + "sha256:ab3ca49afcb47058393b0122428358d2fbe0408cf99f1b58b295cfeb4ed39109", + "sha256:bd6292f565ca46dee4e737ebcc20742e3b5be2b01556dafe169f6c65d088875f", + "sha256:cb924aa3e4a3fb644d0c463cad5bc2572649a6a3f68a7f8e4fbe44aaa6d77e4c", + "sha256:d0fc7a286feac9077ec52a927fc9fe8fe2fabab95426722be4c953c9a8bede92", + "sha256:ddc34786490a6e4ec0a855d401034cbd1242ef186c20d79d2166d6a4bd449577", + "sha256:e34b155e36fa9da7e1b7c738ed7767fc9491a62ec6af70fe9da4a057759edc2d", + "sha256:e5b9e8f6bda48460b7b143c3821b21b452cb3a835e6bbd5dd33aa0c8d3f5137d", + "sha256:e81ebf6c5ee9684be8f2c87563880f93eedd56dd2b6146d8a725b50b7e5adb0f", + "sha256:eb91be369f945f10d3a49f5f9be8b3d0b93a4c2be8f8a5b83b0571b8123e0a7a", + "sha256:f460d1ceb0e4a5dcb2a652db0904224f367c9b3c1470d5a7683c0480e582468b" + ], + "version": "==1.3.1" + }, + "mccabe": { + "hashes": [ + "sha256:ab8a6258860da4b6677da4bd2fe5dc2c659cff31b3ee4f7f5d64e79735b80d42", + "sha256:dd8d182285a0fe56bace7f45b5e7d1a6ebcbf524e8f3bd87eb0f125271b8831f" + ], + "version": "==0.6.1" + }, + "pylint": { + "hashes": [ + "sha256:2c90a24bee8fae22ac98061c896e61f45c5b73c2e0511a4bf53f99ba56e90434", + "sha256:454532779425098969b8f54ab0f056000b883909f69d05905ea114df886e3251" + ], + "index": "pypi", + "version": "==2.0.1" + }, + "six": { + "hashes": [ + "sha256:70e8a77beed4562e7f14fe23a786b54f6296e34344c23bc42f07b15018ff98e9", + "sha256:832dc0e10feb1aa2c68dcc57dbb658f1c7e65b9b61af69048abc87a2db00a0eb" + ], + "version": "==1.11.0" + }, + "wrapt": { + "hashes": [ + "sha256:d4d560d479f2c21e1b5443bbd15fe7ec4b37fe7e53d335d3b9b0a7b1226fe3c6" + ], + "version": "==1.10.11" + } + } } diff --git a/src/day-1-toy/bignum.py b/src/day-1-toy/bignum.py index 77e8d66ffa..84eddd1925 100644 --- a/src/day-1-toy/bignum.py +++ b/src/day-1-toy/bignum.py @@ -1 +1,2 @@ -# Print out 2 to the 65536 power \ No newline at end of file +# Print out 2 to the 65536 power +print(2**65536) \ No newline at end of file diff --git a/src/day-1-toy/datatypes.py b/src/day-1-toy/datatypes.py index f5967611a7..255164083e 100644 --- a/src/day-1-toy/datatypes.py +++ b/src/day-1-toy/datatypes.py @@ -2,7 +2,7 @@ y = "7" # Write a print statement that combines x + y into the integer value 12 -print(x + y) +print(int(y)+ x) # Write a print statement that combines x + y into the string value 57 -print(x + y) \ No newline at end of file +print(str(x)+ y) \ No newline at end of file diff --git a/src/day-1-toy/hello.py b/src/day-1-toy/hello.py index 37968da4d4..2289831365 100644 --- a/src/day-1-toy/hello.py +++ b/src/day-1-toy/hello.py @@ -1 +1,2 @@ -# Write Hello, world \ No newline at end of file +# Write Hello, world +print("Hello, world") \ No newline at end of file diff --git a/src/day-1-toy/lists.py b/src/day-1-toy/lists.py index 6076f340a9..aa9b1176aa 100644 --- a/src/day-1-toy/lists.py +++ b/src/day-1-toy/lists.py @@ -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.extend(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 \ No newline at end of file +# Using a for loop, print all the element values multiplied by 1000 +for i in x: + print(i*1000) \ No newline at end of file diff --git a/src/day-1-toy/modules.py b/src/day-1-toy/modules.py index 5313fc1934..5677cd5866 100644 --- a/src/day-1-toy/modules.py +++ b/src/day-1-toy/modules.py @@ -6,13 +6,13 @@ # 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) # Print out the plaform from sys: -print() +print(sys.platform) # Print out the Python version from sys: -print() +print(sys.version) @@ -21,11 +21,10 @@ # 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()) diff --git a/src/day-1-toy/printf.py b/src/day-1-toy/printf.py index d4bc9abb48..2381c1585f 100644 --- a/src/day-1-toy/printf.py +++ b/src/day-1-toy/printf.py @@ -6,5 +6,5 @@ # y, and z: # x is 10, y is 2.25, z is "I like turtles!" - -# Use the 'format' string method to print the same thing \ No newline at end of file +# Use the 'format' string method to print the same thing +print("x is %d, y is %f, z is %s" % (x, y, z)) \ No newline at end of file From 18e522e0165ab16f85b298fb7e71229ee0d5ae7d Mon Sep 17 00:00:00 2001 From: Alexis Reyes Date: Tue, 31 Jul 2018 23:30:04 -0400 Subject: [PATCH 02/10] up to cal.py --- src/day-1-toy/args.py | 14 +++++++++++--- src/day-1-toy/bar.txt | 1 + src/day-1-toy/cal.py | 1 + src/day-1-toy/comp.py | 9 +++++---- src/day-1-toy/dicts.py | 3 +++ src/day-1-toy/fileio.py | 14 ++++++++------ src/day-1-toy/func.py | 15 ++++++++++++++- src/day-1-toy/scope.py | 2 ++ src/day-1-toy/slice.py | 14 +++++++------- src/day-1-toy/tuples.py | 6 +++++- 10 files changed, 57 insertions(+), 22 deletions(-) create mode 100644 src/day-1-toy/bar.txt diff --git a/src/day-1-toy/args.py b/src/day-1-toy/args.py index 06a830e4c8..ce2ad439c2 100644 --- a/src/day-1-toy/args.py +++ b/src/day-1-toy/args.py @@ -3,14 +3,16 @@ # 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(a,b): + return a+b #def f1(... 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(*args): + #sum something goes here # def f2(... print(f2(1)) # Should print 1 @@ -26,7 +28,8 @@ # 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(a,b=1): + return a+b #? #def f3(... print(f3(1, 2)) # Should print 3 @@ -40,7 +43,12 @@ # key: baz, value: 12 # # Google "python keyword arguments". +#its like **args from above +#do whatyou did dictionaries. +def f4(**kwargs): + for keys, vals in kwargs.items(): + print("") #def f4(... # Should print diff --git a/src/day-1-toy/bar.txt b/src/day-1-toy/bar.txt new file mode 100644 index 0000000000..26c808bf5e --- /dev/null +++ b/src/day-1-toy/bar.txt @@ -0,0 +1 @@ +Hi my name is... \ No newline at end of file diff --git a/src/day-1-toy/cal.py b/src/day-1-toy/cal.py index 2a3771eb5b..ce7bea6fc1 100644 --- a/src/day-1-toy/cal.py +++ b/src/day-1-toy/cal.py @@ -14,3 +14,4 @@ # docs for the calendar module closely. import sys +import calendar diff --git a/src/day-1-toy/comp.py b/src/day-1-toy/comp.py index 083e9b9140..42942494fe 100644 --- a/src/day-1-toy/comp.py +++ b/src/day-1-toy/comp.py @@ -1,13 +1,14 @@ # Write a list comprehension to produce the array [1, 2, 3, 4, 5] +# y = [1,2,3,4,5] as well, but this is a list comprehension -y = [] +y = [i for i in range(1,6)] 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 = [i**3 for i in range(1,10)] print(y) @@ -16,7 +17,7 @@ a = ["foo", "bar", "baz"] -y = [] +y = [i.upper() for i in a] print(y) @@ -26,7 +27,7 @@ x = input("Enter comma-separated numbers: ").split(',') # What do you need between the square brackets to make it work? -y = [] +y = [i for i in x if int(i) % 2 == 0] print(y) diff --git a/src/day-1-toy/dicts.py b/src/day-1-toy/dicts.py index eac1779a42..066322b4e0 100644 --- a/src/day-1-toy/dicts.py +++ b/src/day-1-toy/dicts.py @@ -25,5 +25,8 @@ ] # Write a loop that prints out all the field values for all the waypoints +for vals in waypoints: + print(vals['lat'], vals['lon'], vals['name']) # Add a new waypoint to the list +waypoints.append({"lat": 100, "lon": -500, "name": "The Unknown"}) \ No newline at end of file diff --git a/src/day-1-toy/fileio.py b/src/day-1-toy/fileio.py index bc8e79b7cc..a28849a05e 100644 --- a/src/day-1-toy/fileio.py +++ b/src/day-1-toy/fileio.py @@ -1,12 +1,14 @@ # Use open to open file "foo.txt" for reading - +openFoo = open("foo.txt", "r") # Print all the lines in the file - +for words in openFoo: + print(words) # Close the file - +openFoo.close() # Use open to open file "bar.txt" for writing - +openBar = open("bar.txt", "w") # Use the write() method to write three lines to the file - -# Close the file \ No newline at end of file +openBar.write("Hi my name is...") +# Close the file +openBar.close() \ No newline at end of file diff --git a/src/day-1-toy/func.py b/src/day-1-toy/func.py index 2b7f435ffa..5a0bc2d67b 100644 --- a/src/day-1-toy/func.py +++ b/src/day-1-toy/func.py @@ -1,6 +1,19 @@ # Write a function is_even that will return true if the passed in number is even. +def even_num(y): + if y % 2 == 0: + return y # Read a number from the keyboard num = input("Enter a number: ") -# Print out "Even!" if the number is even. Otherwise print "Odd" \ No newline at end of file +# Print out "Even!" if the number is even. Otherwise print "Odd" + +# So it reads it off the keyboard as a string? +# have to convert to num? + +num = int(num) + +if even_num(num): + print("even") +else: + print("odd") \ No newline at end of file diff --git a/src/day-1-toy/scope.py b/src/day-1-toy/scope.py index 68ecc6c412..045393ce9a 100644 --- a/src/day-1-toy/scope.py +++ b/src/day-1-toy/scope.py @@ -5,6 +5,7 @@ x = 12 def changeX(): + global x x = 99 changeX() @@ -19,6 +20,7 @@ def outer(): y = 120 def inner(): + nonlocal y y = 999 inner() diff --git a/src/day-1-toy/slice.py b/src/day-1-toy/slice.py index 3c6cb38730..f3a5669768 100644 --- a/src/day-1-toy/slice.py +++ b/src/day-1-toy/slice.py @@ -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:6]) # 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() \ No newline at end of file +print(s[7:12]) \ No newline at end of file diff --git a/src/day-1-toy/tuples.py b/src/day-1-toy/tuples.py index ec42b0cdf8..1b56745e20 100644 --- a/src/day-1-toy/tuples.py +++ b/src/day-1-toy/tuples.py @@ -21,6 +21,9 @@ def dist(a, b): # Write a function that prints all the values in a tuple +def print_tuple(t): + for i in t: + print(i) # def print_tuple(... @@ -28,5 +31,6 @@ def dist(a, b): 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? +# A COMMA!! A comma tells python that that value needs to be a tuple print_tuple(u) From 0e8c1dce524ca1b5c766c886acbe39b7089658b6 Mon Sep 17 00:00:00 2001 From: Alexis Reyes Date: Thu, 2 Aug 2018 22:47:46 -0400 Subject: [PATCH 03/10] updates cal, completed obj.py, making logic for adv.py --- src/day-1-toy/cal.py | 4 ++++ src/day-1-toy/obj.py | 22 ++++++++++++++++++++-- src/days-2-4-adv/adv.py | 25 ++++++++++++++++++++++++- src/days-2-4-adv/player.py | 3 +++ src/days-2-4-adv/room.py | 7 ++++++- 5 files changed, 57 insertions(+), 4 deletions(-) diff --git a/src/day-1-toy/cal.py b/src/day-1-toy/cal.py index ce7bea6fc1..f5a0e440a8 100644 --- a/src/day-1-toy/cal.py +++ b/src/day-1-toy/cal.py @@ -15,3 +15,7 @@ import sys import calendar +import datetime + +year = int(input("Enter the year: ")) +month = int(input("Enter Month 1 - 12: ")) \ No newline at end of file diff --git a/src/day-1-toy/obj.py b/src/day-1-toy/obj.py index 84c78a2f53..f3dbeb01cd 100644 --- a/src/day-1-toy/obj.py +++ b/src/day-1-toy/obj.py @@ -1,21 +1,39 @@ # 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 + # 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 # Make a new waypoint "Catacombs", 41.70505, -121.51521 +new_waypoint = Waypoint("Catacombs", 41.70505, -121.51521) + +print(new_waypoint) # Print it # # Without changing the following line, how can you make it print into something # more human-readable? -print(w) +print(new_waypoint.name) # Make a new geocache "Newberry Views", diff 1.5, size 2, 44.052137, -121.41556 +new_geocache = Geocache("Newberry Views", 1.5, 2, 44.052137, -121.41556) # Print it--also make this print more nicely -print(g) +print(new_geocache.size) diff --git a/src/days-2-4-adv/adv.py b/src/days-2-4-adv/adv.py index c9e26b0f85..5e87ad7225 100644 --- a/src/days-2-4-adv/adv.py +++ b/src/days-2-4-adv/adv.py @@ -1,5 +1,5 @@ from room import Room - +from player import Player # Declare all the rooms room = { @@ -38,6 +38,8 @@ # # Make a new player object that is currently in the 'outside' room. +# players attribute is the room it is in. +player = Player(room['outside']) # Write a loop that: # @@ -49,3 +51,24 @@ # Print an error message if the movement isn't allowed. # # If the user enters "q", quit the game. + +done = False +start = False + +while not done: + while not start: + print(player.room.name, player.room.description) + start = True + choice = input("Enter a direction: n, s, e, or w. Enter q to quit. ") + if choice != 'q': + choice += '_to' + else: + break + # print(choice) + if choice == "q": + done = True + elif choice in ["n", "s", "e", "w"]: + break + done = True + + diff --git a/src/days-2-4-adv/player.py b/src/days-2-4-adv/player.py index d79a175029..94edfa5b99 100644 --- a/src/days-2-4-adv/player.py +++ b/src/days-2-4-adv/player.py @@ -1,2 +1,5 @@ # Write a class to hold player information, e.g. what room they are in # currently. +class Player: + def __init__(self, room): + self.room = room diff --git a/src/days-2-4-adv/room.py b/src/days-2-4-adv/room.py index 24c07ad4c8..b501eb40ea 100644 --- a/src/days-2-4-adv/room.py +++ b/src/days-2-4-adv/room.py @@ -1,2 +1,7 @@ # Implement a class to hold room information. This should have name and -# description attributes. \ No newline at end of file +# description attributes. + +class Room: + def __init__(self, name, description): + self.name = name + self.description = description \ No newline at end of file From 6e626f44677b686453a971f19eb093668561ab19 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 6 Aug 2018 22:57:33 -0400 Subject: [PATCH 04/10] inventory added to classes, doesnt display room items --- src/days-2-4-adv/adv.py | 30 +++++++++++++++++++----------- src/days-2-4-adv/item.py | 7 +++++++ src/days-2-4-adv/player.py | 5 ++++- src/days-2-4-adv/room.py | 5 +++-- 4 files changed, 33 insertions(+), 14 deletions(-) create mode 100644 src/days-2-4-adv/item.py diff --git a/src/days-2-4-adv/adv.py b/src/days-2-4-adv/adv.py index 5e87ad7225..301c5375c8 100644 --- a/src/days-2-4-adv/adv.py +++ b/src/days-2-4-adv/adv.py @@ -1,24 +1,25 @@ from room import Room from player import Player +from item import Item # Declare all the rooms room = { 'outside': Room("Outside Cave Entrance", - "North of you, the cave mount beckons"), + "North of you, the cave mount beckons", [ Item('Sharp rock', 'Ouch! This rock is sharp, but useless.') ]), 'foyer': Room("Foyer", """Dim light filters in from the south. Dusty -passages run north and east."""), +passages run north and east.""", []), 'overlook': Room("Grand Overlook", """A steep cliff appears before you, falling into the darkness. Ahead to the north, a light flickers in -the distance, but there is no way across the chasm."""), +the distance, but there is no way across the chasm.""", []), 'narrow': Room("Narrow Passage", """The narrow passage bends here from west -to north. The smell of gold permeates the air."""), +to north. The smell of gold permeates the air.""", []), 'treasure': Room("Treasure Chamber", """You've found the long-lost treasure chamber! Sadly, it has already been completely emptied by -earlier adventurers. The only exit is to the south."""), +earlier adventurers. The only exit is to the south.""", []), } @@ -39,7 +40,7 @@ # Make a new player object that is currently in the 'outside' room. # players attribute is the room it is in. -player = Player(room['outside']) +player = Player('Alexis', room['outside'], ['Mango'] ) # Write a loop that: # @@ -57,18 +58,25 @@ while not done: while not start: - print(player.room.name, player.room.description) + print("\n", player.name, player.room.name, player.room.description) start = True - choice = input("Enter a direction: n, s, e, or w. Enter q to quit. ") + choice = input("\n Enter a direction: n, s, e, or w. Press i to check inventory, or enter q to quit. ").lower() + if choice == 'i': + print("\n ", "Inventory: ") + for item in player.items: + print(" ", item) if choice != 'q': choice += '_to' + if hasattr(player.room, choice): + player.room = getattr(player.room, choice) + print("\n You have entered the" ,player.room.name,",", player.room.description ) else: break # print(choice) if choice == "q": done = True - elif choice in ["n", "s", "e", "w"]: - break - done = True + # elif choice in ["n", "s", "e", "w"]: + # break + # done = True diff --git a/src/days-2-4-adv/item.py b/src/days-2-4-adv/item.py new file mode 100644 index 0000000000..cad287bf74 --- /dev/null +++ b/src/days-2-4-adv/item.py @@ -0,0 +1,7 @@ +class Item: + def __init__( self, name, description ): + self.name = name + self.description = description + + def __str__( self ): + return self.name + ": " + self.description \ No newline at end of file diff --git a/src/days-2-4-adv/player.py b/src/days-2-4-adv/player.py index 94edfa5b99..9a272f5af5 100644 --- a/src/days-2-4-adv/player.py +++ b/src/days-2-4-adv/player.py @@ -1,5 +1,8 @@ # Write a class to hold player information, e.g. what room they are in # currently. + class Player: - def __init__(self, room): + def __init__( self, name, room, items ): self.room = room + self.name = name + self.items = items diff --git a/src/days-2-4-adv/room.py b/src/days-2-4-adv/room.py index b501eb40ea..1033499cc3 100644 --- a/src/days-2-4-adv/room.py +++ b/src/days-2-4-adv/room.py @@ -2,6 +2,7 @@ # description attributes. class Room: - def __init__(self, name, description): + def __init__(self, name, description, items ): self.name = name - self.description = description \ No newline at end of file + self.description = description + self.items = items \ No newline at end of file From 2ff02411f87876552328339436ea82f9374eed34 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 7 Aug 2018 23:28:20 -0400 Subject: [PATCH 05/10] i command working properly, grab item works, dropping items is problematic --- src/days-2-4-adv/adv.py | 50 +++++++++++++++++++++++++--------------- src/days-2-4-adv/room.py | 11 ++++++++- 2 files changed, 42 insertions(+), 19 deletions(-) diff --git a/src/days-2-4-adv/adv.py b/src/days-2-4-adv/adv.py index 301c5375c8..9817b50a3c 100644 --- a/src/days-2-4-adv/adv.py +++ b/src/days-2-4-adv/adv.py @@ -5,21 +5,21 @@ room = { 'outside': Room("Outside Cave Entrance", - "North of you, the cave mount beckons", [ Item('Sharp rock', 'Ouch! This rock is sharp, but useless.') ]), + "North of you, the cave mount beckons", [ Item('Rock', 'Ouch! This rock is sharp, but useless.') ]), 'foyer': Room("Foyer", """Dim light filters in from the south. Dusty -passages run north and east.""", []), +passages run north and east.""", [ Item('Sword', 'Looks strong, but feels weaker than a twig.')]), 'overlook': Room("Grand Overlook", """A steep cliff appears before you, falling into the darkness. Ahead to the north, a light flickers in -the distance, but there is no way across the chasm.""", []), +the distance, but there is no way across the chasm.""", [ Item('Health', 'This can be useful.')]), 'narrow': Room("Narrow Passage", """The narrow passage bends here from west to north. The smell of gold permeates the air.""", []), 'treasure': Room("Treasure Chamber", """You've found the long-lost treasure chamber! Sadly, it has already been completely emptied by -earlier adventurers. The only exit is to the south.""", []), +earlier adventurers. The only exit is to the south.""", [ Item('Ultima', 'So... So shiny, and made of a mystery metal.')]), } @@ -40,7 +40,7 @@ # Make a new player object that is currently in the 'outside' room. # players attribute is the room it is in. -player = Player('Alexis', room['outside'], ['Mango'] ) +player = Player('Alexis', room['outside'], [''] ) # Write a loop that: # @@ -59,24 +59,38 @@ while not done: while not start: print("\n", player.name, player.room.name, player.room.description) + player.room.room_items() start = True - choice = input("\n Enter a direction: n, s, e, or w. Press i to check inventory, or enter q to quit. ").lower() - if choice == 'i': + choice = input("\n Enter a direction: n, s, e, or w. Press i to check inventory, or enter q to quit.\n While in a room, you can press g to grab the item ").lower() + if choice != 'q' and choice != 'i' and choice != 'g' and choice != 'd': + choice += '_to' + if hasattr(player.room, choice): + player.room = getattr(player.room, choice) + print("\n You have entered the" ,player.room.name,",", player.room.description, "\n" ) + player.room.room_items() + else: + print("This way is not allowed! Go another direction!") + elif choice == 'i': print("\n ", "Inventory: ") for item in player.items: print(" ", item) - if choice != 'q': - choice += '_to' - if hasattr(player.room, choice): - player.room = getattr(player.room, choice) - print("\n You have entered the" ,player.room.name,",", player.room.description ) - else: - break - # print(choice) + elif choice == 'g': + grabbing = input("\n Which item would you like to grab? Type the name of the item to put in your inventory...\n") + for i in player.room.items: + if grabbing in i.name: + print("Grabbed item!") + player.items.append(i) + player.room.items.remove(i) + else: + print("No such item exits...\n") + elif choice == 'd': + dropping = input("\n Which item would you like to drop? Type the name of the item to remove from your inventory...\n") + for i in player.items: + if dropping in i: + print("Dropping...") + player.room.items.append(i) + player.items.remove(i) if choice == "q": done = True - # elif choice in ["n", "s", "e", "w"]: - # break - # done = True diff --git a/src/days-2-4-adv/room.py b/src/days-2-4-adv/room.py index 1033499cc3..49473e94d0 100644 --- a/src/days-2-4-adv/room.py +++ b/src/days-2-4-adv/room.py @@ -5,4 +5,13 @@ class Room: def __init__(self, name, description, items ): self.name = name self.description = description - self.items = items \ No newline at end of file + self.items = items + + def room_items(self): + print("Items that can be taken in this room are... \n") + if len(self.items) == 0: + print("Nothing here!") + else: + for item in self.items: + print(item,"\n") + return item \ No newline at end of file From aa10e50b7f7f117be47e9aefad06f775c35688b9 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 7 Aug 2018 23:59:26 -0400 Subject: [PATCH 06/10] dropping feature works now. Thanks Jesse and Frank! --- src/days-2-4-adv/adv.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/days-2-4-adv/adv.py b/src/days-2-4-adv/adv.py index 9817b50a3c..a180391629 100644 --- a/src/days-2-4-adv/adv.py +++ b/src/days-2-4-adv/adv.py @@ -40,7 +40,7 @@ # Make a new player object that is currently in the 'outside' room. # players attribute is the room it is in. -player = Player('Alexis', room['outside'], [''] ) +player = Player('Alexis', room['outside'], [] ) # Write a loop that: # @@ -84,12 +84,17 @@ else: print("No such item exits...\n") elif choice == 'd': + print("Items that are in your inventory to drop...: \n") + for item in player.items: + print(" ", item) dropping = input("\n Which item would you like to drop? Type the name of the item to remove from your inventory...\n") for i in player.items: - if dropping in i: + if dropping == i.name: print("Dropping...") player.room.items.append(i) player.items.remove(i) + else: + print("This item is not in your inventory...") if choice == "q": done = True From b3dbde9c03334604af6bc5f1334d1d23b3e73406 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 8 Aug 2018 23:21:30 -0400 Subject: [PATCH 07/10] treasure, score, and lightsource functional --- src/days-2-4-adv/adv.py | 62 +++++++++++++++++++++++++------------- src/days-2-4-adv/item.py | 24 ++++++++++++++- src/days-2-4-adv/player.py | 8 +++++ src/days-2-4-adv/room.py | 1 + 4 files changed, 73 insertions(+), 22 deletions(-) diff --git a/src/days-2-4-adv/adv.py b/src/days-2-4-adv/adv.py index a180391629..c995490a3a 100644 --- a/src/days-2-4-adv/adv.py +++ b/src/days-2-4-adv/adv.py @@ -1,11 +1,11 @@ from room import Room from player import Player -from item import Item +from item import Item, Treasure, LightSource # Declare all the rooms room = { 'outside': Room("Outside Cave Entrance", - "North of you, the cave mount beckons", [ Item('Rock', 'Ouch! This rock is sharp, but useless.') ]), + "North of you, the cave mount beckons", [ LightSource('Rock', 'Ouch! This rock is sharp, but useless.') ]), 'foyer': Room("Foyer", """Dim light filters in from the south. Dusty passages run north and east.""", [ Item('Sword', 'Looks strong, but feels weaker than a twig.')]), @@ -15,7 +15,7 @@ the distance, but there is no way across the chasm.""", [ Item('Health', 'This can be useful.')]), 'narrow': Room("Narrow Passage", """The narrow passage bends here from west -to north. The smell of gold permeates the air.""", []), +to north. The smell of gold permeates the air.""", [ Treasure('Amethyst', 'Looks expensive.', 100) ]), 'treasure': Room("Treasure Chamber", """You've found the long-lost treasure chamber! Sadly, it has already been completely emptied by @@ -34,6 +34,8 @@ room['narrow'].n_to = room['treasure'] room['treasure'].s_to = room['narrow'] +room['outside'].is_light = True + # # Main # @@ -56,37 +58,52 @@ done = False start = False + while not done: + + if player.score >= 200: + print("You win the game!") + done = True + while not start: - print("\n", player.name, player.room.name, player.room.description) - player.room.room_items() - start = True - choice = input("\n Enter a direction: n, s, e, or w. Press i to check inventory, or enter q to quit.\n While in a room, you can press g to grab the item ").lower() - if choice != 'q' and choice != 'i' and choice != 'g' and choice != 'd': + print("\n", player.name, player.room.name, player.room.description) + player.room.room_items() + start = True + choice = input("\nEnter a direction: n, s, e, or w. \nPress i to check inventory, or enter q to quit.\nType score to see your score. \nWhile in a room, you can press g to grab the item, or d to drop an item. ").lower() + + if choice != 'q' and choice != 'i' and choice != 'g' and choice != 'd' and choice != 'score': choice += '_to' if hasattr(player.room, choice): player.room = getattr(player.room, choice) - print("\n You have entered the" ,player.room.name,",", player.room.description, "\n" ) - player.room.room_items() + if player.room.is_light: + print("\n You have entered the" ,player.room.name,",", player.room.description, "\n" ) + player.room.room_items() + else: + print("\nIt's pitch black\n") + for i in player.items: + if isinstance(i, LightSource): + print("\n You have entered the" ,player.room.name,",", player.room.description, "\n" ) + player.room.room_items() + else: - print("This way is not allowed! Go another direction!") + print("\n This way is not allowed! Go another direction! \n") + elif choice == 'i': - print("\n ", "Inventory: ") - for item in player.items: - print(" ", item) + player.inv_check( player ) + elif choice == 'g': grabbing = input("\n Which item would you like to grab? Type the name of the item to put in your inventory...\n") + for i in player.room.items: - if grabbing in i.name: - print("Grabbed item!") - player.items.append(i) - player.room.items.remove(i) - else: - print("No such item exits...\n") + if grabbing == i.name: + i.on_grab( player ) + elif choice == 'd': print("Items that are in your inventory to drop...: \n") + for item in player.items: print(" ", item) + dropping = input("\n Which item would you like to drop? Type the name of the item to remove from your inventory...\n") for i in player.items: if dropping == i.name: @@ -94,7 +111,10 @@ player.room.items.append(i) player.items.remove(i) else: - print("This item is not in your inventory...") + print("\n This item is currently not in your inventory... \n") + + elif choice == 'score': + print("\n You have a score of %d...\n " % player.score) if choice == "q": done = True diff --git a/src/days-2-4-adv/item.py b/src/days-2-4-adv/item.py index cad287bf74..c8f551bb57 100644 --- a/src/days-2-4-adv/item.py +++ b/src/days-2-4-adv/item.py @@ -4,4 +4,26 @@ def __init__( self, name, description ): self.description = description def __str__( self ): - return self.name + ": " + self.description \ No newline at end of file + return self.name + ": " + self.description + + def on_grab( self, player ): + print("\nGrabbed item!\n") + player.items.append(self) + player.room.items.remove(self) + +class Treasure(Item): + def __init__( self, name, description, value ): + super().__init__( name, description ) + self.value = value + self.grabbed_treasure = False + + def on_grab( self, player ): + super().on_grab( player ) + if self.grabbed_treasure == False: + player.score += self.value + self.grabbed_treasure = True + +class LightSource(Item): + def __init__( self, name, description ): + super().__init__( name, description ) + self.lightsource = True \ No newline at end of file diff --git a/src/days-2-4-adv/player.py b/src/days-2-4-adv/player.py index 9a272f5af5..d6bc88689e 100644 --- a/src/days-2-4-adv/player.py +++ b/src/days-2-4-adv/player.py @@ -6,3 +6,11 @@ def __init__( self, name, room, items ): self.room = room self.name = name self.items = items + self.score = 0 + + def inv_check( self, player ): + print("\n ", "Inventory: ") + for item in player.items: + print(" ", item) + + diff --git a/src/days-2-4-adv/room.py b/src/days-2-4-adv/room.py index 49473e94d0..59e2e20ac8 100644 --- a/src/days-2-4-adv/room.py +++ b/src/days-2-4-adv/room.py @@ -6,6 +6,7 @@ def __init__(self, name, description, items ): self.name = name self.description = description self.items = items + self.is_light = False def room_items(self): print("Items that can be taken in this room are... \n") From 4fa5b31a5ee5e91db8e334d18fa93a6cb7e49667 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 8 Aug 2018 23:27:37 -0400 Subject: [PATCH 08/10] light source Easter Egg added, confirmed light source works --- src/days-2-4-adv/adv.py | 11 +++++------ src/days-2-4-adv/item.py | 2 +- src/days-2-4-adv/room.py | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/days-2-4-adv/adv.py b/src/days-2-4-adv/adv.py index c995490a3a..2ab24df439 100644 --- a/src/days-2-4-adv/adv.py +++ b/src/days-2-4-adv/adv.py @@ -1,11 +1,11 @@ from room import Room from player import Player -from item import Item, Treasure, LightSource +from item import Item, Treasure, BlznIt # Declare all the rooms room = { 'outside': Room("Outside Cave Entrance", - "North of you, the cave mount beckons", [ LightSource('Rock', 'Ouch! This rock is sharp, but useless.') ]), + "North of you, the cave mount beckons", [ BlznIt('Rock', 'Ouch! This rock is sharp, but useless.') ]), 'foyer': Room("Foyer", """Dim light filters in from the south. Dusty passages run north and east.""", [ Item('Sword', 'Looks strong, but feels weaker than a twig.')]), @@ -34,7 +34,7 @@ room['narrow'].n_to = room['treasure'] room['treasure'].s_to = room['narrow'] -room['outside'].is_light = True +room['outside'].is_lit = True # # Main @@ -75,16 +75,15 @@ choice += '_to' if hasattr(player.room, choice): player.room = getattr(player.room, choice) - if player.room.is_light: + if player.room.is_lit: print("\n You have entered the" ,player.room.name,",", player.room.description, "\n" ) player.room.room_items() else: print("\nIt's pitch black\n") for i in player.items: - if isinstance(i, LightSource): + if isinstance(i, BlznIt): print("\n You have entered the" ,player.room.name,",", player.room.description, "\n" ) player.room.room_items() - else: print("\n This way is not allowed! Go another direction! \n") diff --git a/src/days-2-4-adv/item.py b/src/days-2-4-adv/item.py index c8f551bb57..033aebf44c 100644 --- a/src/days-2-4-adv/item.py +++ b/src/days-2-4-adv/item.py @@ -23,7 +23,7 @@ def on_grab( self, player ): player.score += self.value self.grabbed_treasure = True -class LightSource(Item): +class BlznIt(Item): def __init__( self, name, description ): super().__init__( name, description ) self.lightsource = True \ No newline at end of file diff --git a/src/days-2-4-adv/room.py b/src/days-2-4-adv/room.py index 59e2e20ac8..b99195459f 100644 --- a/src/days-2-4-adv/room.py +++ b/src/days-2-4-adv/room.py @@ -6,7 +6,7 @@ def __init__(self, name, description, items ): self.name = name self.description = description self.items = items - self.is_light = False + self.is_lit = False def room_items(self): print("Items that can be taken in this room are... \n") From bb3103f097ec1ed393325a183f901a9726a603ca Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 8 Aug 2018 23:43:00 -0400 Subject: [PATCH 09/10] edge case if item is an item, but not a lightsource to drop normall, and not with special message --- src/days-2-4-adv/adv.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/days-2-4-adv/adv.py b/src/days-2-4-adv/adv.py index 2ab24df439..544b0af5d0 100644 --- a/src/days-2-4-adv/adv.py +++ b/src/days-2-4-adv/adv.py @@ -106,9 +106,16 @@ dropping = input("\n Which item would you like to drop? Type the name of the item to remove from your inventory...\n") for i in player.items: if dropping == i.name: - print("Dropping...") - player.room.items.append(i) - player.items.remove(i) + if isinstance(i, BlznIt): + print("\nIt's not wise to drop your source of light!\n") + print("Dropping...") + player.room.items.append(i) + player.items.remove(i) + elif not isinstance(i, BlznIt): + print("Dropping...") + player.room.items.append(i) + player.items.remove(i) + else: print("\n This item is currently not in your inventory... \n") From dd2d7efe80ae3f65dbf2091c64ec7f7c76aeb4d1 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 9 Aug 2018 22:31:42 -0400 Subject: [PATCH 10/10] added a monster class, monster, sequence, and a battle sequence --- src/days-2-4-adv/adv.py | 24 ++++++++++++++++++++++-- src/days-2-4-adv/monster.py | 4 ++++ 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 src/days-2-4-adv/monster.py diff --git a/src/days-2-4-adv/adv.py b/src/days-2-4-adv/adv.py index 544b0af5d0..5dc6365c6e 100644 --- a/src/days-2-4-adv/adv.py +++ b/src/days-2-4-adv/adv.py @@ -1,8 +1,15 @@ from room import Room from player import Player from item import Item, Treasure, BlznIt +from monster import Monster +import random +import time # Declare all the rooms +monster = { + 'spider': Monster("Big Creepy Spider", "Huge hairy legs that ooze a stick substance") +} + room = { 'outside': Room("Outside Cave Entrance", "North of you, the cave mount beckons", [ BlznIt('Rock', 'Ouch! This rock is sharp, but useless.') ]), @@ -42,7 +49,7 @@ # Make a new player object that is currently in the 'outside' room. # players attribute is the room it is in. -player = Player('Alexis', room['outside'], [] ) +player = Player('Alexis', room['outside'], []) # Write a loop that: # @@ -57,6 +64,7 @@ done = False start = False +battle = False while not done: @@ -89,10 +97,21 @@ elif choice == 'i': player.inv_check( player ) + battle_start = random.randint(0, 10) + if battle_start <= 3: + battle = True + while battle: + print("\nWhile checking your inventory, a huge monster appeared before you!\n") + time.sleep(1) + print("\n", monster['spider'].name, monster['spider'].description) + time.sleep(2) + print("... The monster killed you. Sorry for your loss.\n") + battle = False + choice = 'q' + elif choice == 'g': grabbing = input("\n Which item would you like to grab? Type the name of the item to put in your inventory...\n") - for i in player.room.items: if grabbing == i.name: i.on_grab( player ) @@ -122,6 +141,7 @@ elif choice == 'score': print("\n You have a score of %d...\n " % player.score) if choice == "q": + print("Game Over.") done = True diff --git a/src/days-2-4-adv/monster.py b/src/days-2-4-adv/monster.py new file mode 100644 index 0000000000..9f15e87a31 --- /dev/null +++ b/src/days-2-4-adv/monster.py @@ -0,0 +1,4 @@ +class Monster: + def __init__( self, name, description ): + self.name = name + self.description = description \ No newline at end of file