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
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ name = "pypi"
[packages]

[dev-packages]
pylint = "*"

[requires]
python_version = "3"
117 changes: 115 additions & 2 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 14 additions & 5 deletions src/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@
# the sum. This is what you'd consider to be a regular, normal function.

# YOUR CODE HERE

def f1(a, b):
return a + b
print(f1(1, 2))

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

# YOUR CODE HERE
def f2(*args):
z = 0
for a in args:
z += a
return z

print(f2(1)) # Should print 1
print(f2(1, 3)) # Should print 4
Expand All @@ -21,14 +27,15 @@
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.

# YOUR CODE HERE

def f3(farg, sarg = 1):
return farg + sarg
print(f3(1, 2)) # Should print 3
print(f3(8)) # Should print 9

Expand All @@ -42,7 +49,9 @@
# Google "python keyword arguments".

# YOUR CODE HERE

def f4(**kwargs):
for x, y in kwargs.items():
print(f'key: {x}, value: {y}')
# Should print
# key: a, value: 12
# key: b, value: 30
Expand All @@ -60,4 +69,4 @@
}

# What thing do you have to add to make this work?
f4(d)
f4(**d)
3 changes: 3 additions & 0 deletions src/bar.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This is a test
This is another test
This should have three lines
4 changes: 3 additions & 1 deletion src/bignum.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Print out 2 to the 65536 power
# (try doing the same thing in the JS console and see what it outputs)

# YOUR CODE HERE
# YOUR CODE HERE

print(2 ** 65536)
23 changes: 22 additions & 1 deletion src/cal.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,25 @@

import sys
import calendar
from datetime import datetime
from datetime import datetime

now = datetime.now()

def createCal(month = now.month, year=now.year):
c = calendar.TextCalendar(firstweekday=6)
cal = c.formatmonth(year, month)
print(cal)

if len(sys.argv) > 1:
if len(sys.argv) > 2:
if not sys.argv[1].isdecimal():
print('Please input the month and year as numbers')
else:
createCal(int(sys.argv[1]), int(sys.argv[2]))
else:
if not sys.argv[1].isdecimal():
print('Please input the month and year as numbers')
else:
createCal(int(sys.argv[1]))
else:
createCal()
24 changes: 21 additions & 3 deletions src/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,46 @@
# constructor

# YOUR CODE HERE

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. Look up the `super` method.

# YOUR CODE HERE
class Waypoint(LatLon):
def __init__(self, name, lat, lon):
super().__init__(lat, lon)
self.name = name

def __str__(self):
return ' "'+self.name+'", '+str(self.lat)+', '+str(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?

# YOUR CODE HERE
class Geocache(Waypoint):
def __init__(self, name, difficulty, size, lat, lon):
super().__init__(name, lat, lon)
self.difficulty = difficulty
self.size = size

def __str__(self):
return ' "'+self.name+'", diff '+str(self.difficulty)+', size '+str(self.size)+', '+str(self.lat)+', '+str(self.lon)+' '

# Make a new waypoint and print it out: "Catacombs", 41.70505, -121.51521

# YOUR CODE HERE

waypoint = Waypoint("Catacombs", 41.70505, -121.51521)
# Without changing the following line, how can you make it print into something
# more human-readable? Hint: Look up the `object.__str__` method
print(waypoint)

# Make a new geocache "Newberry Views", diff 1.5, size 2, 44.052137, -121.41556

# YOUR CODE HERE

geocache = Geocache("Newberry Views", 1.5, 2, 44.052137, -121.41556)
# Print it--also make this print more nicely
print(geocache)
8 changes: 4 additions & 4 deletions src/comprehensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@

# Write a list comprehension to produce the array [1, 2, 3, 4, 5]

y = []
y = [x+1 for x in range(5)]

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 @@ -26,7 +26,7 @@

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

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

print(y)

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

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

print(y)
5 changes: 3 additions & 2 deletions src/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
# Write a print statement that combines x + y into the integer value 12

# YOUR CODE HERE

print(x + int(y))

# Write a print statement that combines x + y into the string value 57

# YOUR CODE HERE
# YOUR CODE HERE
print(f'{x}{y}')
12 changes: 9 additions & 3 deletions src/dictionaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,16 @@

# Add a new waypoint to the list
# YOUR CODE HERE

waypoints.append({ "lat": 45, "lon": -25, "name": "Awesome town"})
print(waypoints)
# Modify the dictionary with name "a place" such that its longitude
# value is -130 and change its name to "not a real place"
# YOUR CODE HERE

waypoints[0]["lon"] = -130
waypoints[0]["name"] = "not a real place"
print(waypoints)
# Write a loop that prints out all the field values for all the waypoints
# YOUR CODE HERE
# YOUR CODE HERE
for a in waypoints:
for b in a:
print(a[b])
9 changes: 7 additions & 2 deletions src/file_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@
# Print all the contents of the file, then close the file

# YOUR CODE HERE

f = open('foo.txt', 'r')
print(f.read())
f.close()
# Open up a file called "bar.txt" (which doesn't exist yet) for
# writing. Write three lines of arbitrary content to that file,
# then close the file. Open up "bar.txt" and inspect it to make
# sure that it contains what you expect it to contain

# YOUR CODE HERE
# YOUR CODE HERE
b = open('bar.txt', 'w')
b.write('This is a test\nThis is another test\nThis should have three lines')
b.close()
Loading