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

Kelly Manahan #2

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion src/day-1-toy/args.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Experiment with positional arguments, arbitrary arguments, and keyword
# arguments.
# arguments

# 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.
Expand Down
Empty file added src/day-1-toy/bar.txt
Empty file.
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)
5 changes: 5 additions & 0 deletions src/day-1-toy/cal.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@
# docs for the calendar module closely.

import sys
import calendar

year = int(input("enter year:"))
month = int(input("enter month:"))
print(calendar.month(year, month))
8 changes: 4 additions & 4 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 = [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 (10)]

print(y)

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

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

y = []
y = [i.upper() for i 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 = [i for i in x if int(i) % 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)
4 changes: 3 additions & 1 deletion src/day-1-toy/dicts.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,7 @@
]

# Write a loop that prints out all the field values for all the waypoints

for w in waypoints:
print(w['lat'], w['lon'], w['name'])
# Add a new waypoint to the list
waypoints.append({'lat':1, 'lon':2, 'name':'nowhere'})# doesnt seem to add waypoint
12 changes: 8 additions & 4 deletions src/day-1-toy/fileio.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
# Use open to open file "foo.txt" for reading
file = open('foo.txt', 'r')

# Print all the lines in the file
for line in file:
print(line)

# Close the file

file.close()

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

file = open('bar.txt', 'w')
# Use the write() method to write three lines to the file

# Close the file
file.write(3)
# Close the file
file.close()
9 changes: 8 additions & 1 deletion src/day-1-toy/func.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,11 @@
# 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"
def is_even(num):
if int(num) % 2 == 0:
print("even")
else:
print("odd")

is_even(num)
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')
14 changes: 8 additions & 6 deletions src/day-1-toy/lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,25 @@
# For the following, DO NOT USE AN ASSIGNMENT (=).

# Change x so that it is [1, 2, 3, 4]
# [command here]
x.insert(3,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.pop(4)
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]
x.count
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 i in x:
print((i * 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 @@ -9,10 +9,11 @@


# Print out the plaform from sys:
print()
for argv in sys.argv:
print(argv)

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



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())

28 changes: 26 additions & 2 deletions src/day-1-toy/obj.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,45 @@
# 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 change(self):
return "{}: latitude {}, longitude {}".format(
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.size = size
self.name = name
self.difficulty = difficulty
def change(self):
return "{}: difficulty {}, size {}, latitude {}, longitude {}".format(
self.name, self.difficulty, self.size, self.lat, self.lon)
# Make a new waypoint "Catacombs", 41.70505, -121.51521
newWaypoint = Waypoint("Catacombs", 41.70505, -121.51521)

# Print it
#
print(newWaypoint.change())

# Without changing the following line, how can you make it print into something
# more human-readable?
w = newWaypoint.change()
print(w)

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

# Print it--also make this print more nicely
g = newGeocache.change()
print(g)
5 changes: 3 additions & 2 deletions src/day-1-toy/printf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# 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('x is %d, y is %.2f, z is "%s"' % (x,y,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 {:.2f}, z is "{}"'.format(x, y, z))
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[-2])

# 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:6])

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

# For string s...

s = "Hello, world!"

# Output just the 8th-12th characters: "world"
print()
print(s[8:13])
7 changes: 4 additions & 3 deletions src/day-1-toy/tuples.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ def dist(a, b):

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

# def print_tuple(...

def print_tuple(t):
for i in t:
print(i)
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