Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
4835521
initial afterlecture
sbowl001 Jul 31, 2018
d4bdf92
bignum
sbowl001 Jul 31, 2018
4e130d1
datatypes
sbowl001 Jul 31, 2018
c21f0b3
modules done
sbowl001 Jul 31, 2018
3a94ab4
prinf prints one extra 0
sbowl001 Jul 31, 2018
da903a8
lists
sbowl001 Jul 31, 2018
254945d
working on tuples
sbowl001 Jul 31, 2018
f3f7e3b
done printf
sbowl001 Aug 1, 2018
b34bea5
errors with tuples
sbowl001 Aug 1, 2018
174e559
slice
sbowl001 Aug 1, 2018
e156692
last problem for comp
sbowl001 Aug 1, 2018
1916ccf
tuples done
sbowl001 Aug 2, 2018
5f40a32
func done
sbowl001 Aug 2, 2018
f69b615
attempt dicts
sbowl001 Aug 2, 2018
2ecde8d
complete tuples
sbowl001 Aug 2, 2018
78e6219
working on args
sbowl001 Aug 2, 2018
40cae8c
comp done
sbowl001 Aug 3, 2018
407c110
args done
sbowl001 Aug 3, 2018
13df095
some dict solution, not best
sbowl001 Aug 3, 2018
e084c65
scope done
sbowl001 Aug 3, 2018
c9040b1
fileio working
sbowl001 Aug 3, 2018
9323df7
something wrong with cal
sbowl001 Aug 3, 2018
582a8ae
almost ok with obj
sbowl001 Aug 3, 2018
0e0b589
args fixed
sbowl001 Aug 5, 2018
ad44050
another way for bignum
sbowl001 Aug 5, 2018
2853d74
initial afterlecture
sbowl001 Jul 31, 2018
2169b34
bignum
sbowl001 Jul 31, 2018
273a478
datatypes
sbowl001 Jul 31, 2018
47bda8d
modules done
sbowl001 Jul 31, 2018
fcb952c
prinf prints one extra 0
sbowl001 Jul 31, 2018
df34f4e
lists
sbowl001 Jul 31, 2018
39d9a36
working on tuples
sbowl001 Jul 31, 2018
2f1b2fb
done printf
sbowl001 Aug 1, 2018
eae7fd1
errors with tuples
sbowl001 Aug 1, 2018
cb2537e
slice
sbowl001 Aug 1, 2018
aa69fe8
last problem for comp
sbowl001 Aug 1, 2018
0b6f12a
tuples done
sbowl001 Aug 2, 2018
9a39ac0
func done
sbowl001 Aug 2, 2018
1ab38e2
attempt dicts
sbowl001 Aug 2, 2018
31deb6f
complete tuples
sbowl001 Aug 2, 2018
1a43e21
working on args
sbowl001 Aug 2, 2018
16ceaad
comp done
sbowl001 Aug 3, 2018
00a09f5
args done
sbowl001 Aug 3, 2018
3f0b51e
some dict solution, not best
sbowl001 Aug 3, 2018
0871630
scope done
sbowl001 Aug 3, 2018
312d47b
fileio working
sbowl001 Aug 3, 2018
daf2916
something wrong with cal
sbowl001 Aug 3, 2018
c9a30c2
almost ok with obj
sbowl001 Aug 3, 2018
6be407d
args fixed
sbowl001 Aug 5, 2018
af4ad76
another way for bignum
sbowl001 Aug 5, 2018
7bcf5aa
Merge branch 'master' of https://github.com/sbowl001/Intro-Python
sbowl001 Aug 5, 2018
eea8e94
new slice
sbowl001 Aug 5, 2018
ec74db0
new print
sbowl001 Aug 5, 2018
98e76e9
dicts
sbowl001 Aug 5, 2018
2079a69
comp
sbowl001 Aug 5, 2018
92c1c82
cal
sbowl001 Aug 5, 2018
0369e7e
modules.py
sbowl001 Aug 5, 2018
706b7d7
game
sbowl001 Aug 5, 2018
f375a44
init
sbowl001 Aug 6, 2018
c834c13
with solution lecture
sbowl001 Aug 6, 2018
af8f8f6
adding self-created rooms
sbowl001 Aug 7, 2018
539fc6c
directions working, need to update descriptions
sbowl001 Aug 7, 2018
95183e6
groundwork for displaying item message
sbowl001 Aug 7, 2018
b4e95bf
something wrong with action
sbowl001 Aug 7, 2018
0c43e9c
grab and drop working
sbowl001 Aug 8, 2018
b97f923
code for i not working
sbowl001 Aug 8, 2018
991ce24
not working
sbowl001 Aug 8, 2018
20b2d15
cannot get i to work on action line but works on cmd lines/ bug when…
sbowl001 Aug 8, 2018
835405d
adding crayons
sbowl001 Aug 9, 2018
4ae2f58
added inventory message
sbowl001 Aug 9, 2018
faf52a2
fixed bug
sbowl001 Aug 9, 2018
2c4382c
added score display
sbowl001 Aug 10, 2018
53a9b38
treasure working
sbowl001 Aug 10, 2018
83fc3f8
quick crayon
sbowl001 Aug 10, 2018
d9f1ea1
latest
sbowl001 May 6, 2020
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
31 changes: 25 additions & 6 deletions src/day-1-toy/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.

#def f1(...

print(f1(1, 2))
def f1(arg1, arg2):
return arg1 + arg2
print("hello", 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):
total = 0
for i in args:
total += i
return total

print(f2(1)) # Should print 1
print(f2(1, 3)) # Should print 4
Expand All @@ -21,14 +27,25 @@
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(*args):
# total = 0
# if len(args) > 1:
# for i in args:
# total += i
# else:
# for i in args:
# total += i + 1
# return total

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

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

#def f4(...

def f4(**kwargs):
for key, value in kwargs.items():
print(f'key: {key}, value: {value}')
# Should print
# key: a, value: 12
# key: b, value: 30
Expand All @@ -60,4 +79,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 @@
Hi
This is
a new line
6 changes: 5 additions & 1 deletion src/day-1-toy/bignum.py
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
# Print out 2 to the 65536 power
# Print out 2 to the 65536 power

print( 2 ** 65536)

# print (pow(2, 65536))
35 changes: 35 additions & 0 deletions src/day-1-toy/cal.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,38 @@
# docs for the calendar module closely.

import sys
import calendar
import datetime

month = sys.argv[1]
year = sys.argv[2]
print(str(month) + ", " + str(year))

if month == None:
month = 8

if year == None:
year = 2018

myCal = calendar.TextCalendar()
print( myCal.formatmonth( int(year), int(month)))


# current = datetime.datetime.now()
# cal = calendar.TextCalendar()

# year = input("Enter 4 Digit Year: ")
# month = input("Enter Month 1 - 12: ")

# if len(sys.argv) == 3:
# year = int(sys.argv[1])
# month = int(sys.argv[2])
# print(cal.formatmonth(int(year), int(month)))
# else:
# year = current.year
# month = current.month
# print(cal.formatmonth(int(year), int(month)))




9 changes: 5 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(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 = [str.upper() for str in a]

print(y)

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

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

print(y)

# or y = [int(num) for num in x if int(num) %2 == 0]
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)
17 changes: 17 additions & 0 deletions src/day-1-toy/dicts.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,26 @@
"lat": 43,
"lon": -122,
"name": "a third place"
},
{
"lat": 42,
"lon": -333,
"name": "a new world"
}
]

# Write a loop that prints out all the field values for all the waypoints
# print([key for key in waypoints])
# for i in waypoints:
# print(i["lat"])
# print(i["lon"])
# print(i["name"])

for w in waypoints:
print( str(w["lat"]) + " " + str(w["lon"]) + " " + str(w["name"]))

# Add a new waypoint to the list
waypoints.append({"lat": 44, "lon": -22, "name": "newwe"})

for w in waypoints:
print( str(w["lat"]) + " " + str(w["lon"]) + " " + str(w["name"]))
13 changes: 10 additions & 3 deletions src/day-1-toy/fileio.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
# 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
file.write("Hi\n")
file.write("This is\n")
file.write("a new line")

# Close the file
# Close the file
file.close()
6 changes: 6 additions & 0 deletions src/day-1-toy/func.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,10 @@
# Read a number from the keyboard
num = input("Enter a number: ")

def is_even(num):
if int(num) % 2 == 0:
return "Even!"
else:
return "Odd"
print(is_even(num))
# Print out "Even!" if the number is even. Otherwise print "Odd"
4 changes: 3 additions & 1 deletion src/day-1-toy/hello.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# Write Hello, world
# Write Hello, world

print("Hello, world")
9 changes: 8 additions & 1 deletion src/day-1-toy/lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,29 @@

# 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) #x = 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 i in x:
print(i * 1000)
14 changes: 9 additions & 5 deletions src/day-1-toy/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@

# Print out the command line arguments in sys.argv, one per line:

# print(sys.argv[0])
for arg in sys.argv:
print(arg)

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

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



Expand All @@ -21,11 +25,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())

24 changes: 21 additions & 3 deletions src/day-1-toy/obj.py
Original file line number Diff line number Diff line change
@@ -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):
LatLon.__init__(self, lat, lon)
self.name = name
def __str__(self):
return "Name: " + self.name + "\tLat: " + str(self.lat) + "\tLon: " + 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?

# Make a new waypoint "Catacombs", 41.70505, -121.51521
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 "Name: " + self.name + "\tDifficulty: " + str(self.difficulty) + "\tSize: " + str(self.size)

# Make a new waypoint "Catacombs", 41.70505, -121.51521
w = Waypoint("Catacombs", 41.3939, -22222)
# Print it
#
# 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

g = Geocache("Newberry Views", 1.5, 2, 33.333, -2222 )
# Print it--also make this print more nicely
print(g)
5 changes: 4 additions & 1 deletion src/day-1-toy/printf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
# 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
# print( 'x is {0}, y is {1}, z is "{2}"'.format(x, y, z))

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

def changeX():
global x
x = 99

changeX()

# This prints 12. What do we have to modify in changeX() to get it to print 99?
Expand All @@ -19,6 +20,7 @@ def outer():
y = 120

def inner():
nonlocal y
y = 999

inner()
Expand Down
Loading