Skip to content

Commit 61e12c0

Browse files
committed
completed printGrid, lists, and dict labs
1 parent afca745 commit 61e12c0

File tree

4 files changed

+85
-33
lines changed

4 files changed

+85
-33
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
One night--it was on the twentieth of March, 1888--I was
2+
returning from a journey to a patient (for I had now returned to
3+
civil practice), when my way led me through Baker Street. As I
4+
passed the well-remembered door, which must always be associated
5+
in my mind with my wooing, and with the dark incidents of the
6+
Study in Scarlet, I was seized with a keen desire to see Holmes
7+
again, and to know how he was employing his extraordinary powers.
8+
His rooms were brilliantly lit, and, even as I looked up, I saw
9+
his tall, spare figure pass twice in a dark silhouette against
10+
the blind. He was pacing the room swiftly, eagerly, with his head
11+
sunk upon his chest and his hands clasped behind him. To me, who
12+
knew his every mood and habit, his attitude and manner told their
13+
own story. He was at work again. He had risen out of his
14+
drug-created dreams and was hot upon the scent of some new
15+
problem. I rang the bell and was shown up to the chamber which
16+
had formerly been in part my own.

students/susanRees/session02/PrintGrid.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,38 @@ def print_column():
2121
print_column()
2222
print_row()
2323

24-
2524
print_grid(10)
2625

2726

2827
def second_grid(x, y):
29-
n = (y-1)
30-
for n in range(0, n):
31-
def print_rows():
28+
n = (x + 1)
29+
m = (n - 1)
30+
for m in range(0, m):
31+
def print_row():
3232
print('+', end=' '),
3333
print('-' * y, end=' '),
34-
print_rows()
35-
print('+')
36-
def print_columns():
34+
def print_rows():
35+
n = (x + 1)
36+
m = (n - 1)
37+
for m in range (0, m):
38+
print_row()
39+
def print_column():
3740
print('|', end=' '),
3841
print(' ' * y, end=' '),
39-
print_columns()
40-
print('|')
42+
def print_columns():
43+
n = (x + 1)
44+
m = (n - 1)
45+
for m in range (0, m):
46+
print_column()
47+
print_rows()
48+
print('+')
49+
def print_mult_columns():
50+
n = (y + 1)
51+
m = (n - 1)
52+
for m in range (0, m):
53+
print_columns()
54+
print('|')
55+
print_mult_columns()
4156
print_rows()
4257
print('+')
43-
second_grid(3, 4)
58+
second_grid(4, 10)

students/susanRees/session03/Lists.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,16 @@
9595

9696

9797
# Make a copy of the original list
98-
backwards_fruits = fruits[0:-1]
98+
backwards_fruits = fruits[:]
9999

100100
# reverse the letters in each fruit in the copy.
101-
# for bwards in backwards_fruits:
102-
103-
# print(backwards_fruits)
101+
for item in backwards_fruits[:]:
102+
bward_item = item[::-1]
103+
backwards_fruits.append(bward_item)
104104

105105
# Delete the last item of the original list.
106-
# fruits.pop(-1)
106+
fruits.pop(-1)
107107

108108
# Display the original list and the copy.
109-
# print(fruits)
110-
# print(backwards_fruits)
109+
print(fruits)
110+
print(backwards_fruits)
Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,72 @@
11
# Create a dictionary containing “name”, “city”, and “cake”
22
# for “Chris” from “Seattle” who likes “Chocolate”.
3-
dict = {'name': "Chris", 'city': "Seattle", 'cake': "Chocolate"}
3+
stuff = {'name': "Chris", 'city': "Seattle", 'cake': "Chocolate"}
44

55
# Display the dictionary.
6-
print(dict)
6+
print(stuff)
77

88
# Delete the entry for “cake”.
9-
dict.pop('cake')
9+
stuff.pop('cake')
1010

1111
# Display the dictionary.
12-
print(dict)
12+
print(stuff)
1313

1414
# Add an entry for “fruit” with “Mango” and display the dictionary.
15-
dict.update({'fruit': "Mango"})
15+
stuff.update({'fruit': "Mango"})
1616

17-
print(dict)
17+
print(stuff)
1818

1919
# Display the dictionary keys.
20-
print(dict.keys())
20+
print(stuff.keys())
2121

2222

2323
# Display the dictionary values.
24-
print(dict.values())
24+
print(stuff.values())
2525

2626
# Display whether or not “cake” is a key in the dictionary (i.e. False) (now).
27-
print("True" if 'cake' in dict else "False")
27+
print("True" if 'cake' in stuff else "False")
2828

2929
# Display whether or not “Mango” is a value in the dictionary (i.e. True).
30-
print("True" if "Mango" in dict.values() else "False")
30+
print("True" if "Mango" in stuff.values() else "False")
3131

3232
# Using the dictionary from item 1:
3333
# Make a dictionary using same keys but with the number of ‘t’s in each value.
34-
# Not sure I understand the assingment...
34+
stuff = {'name': "Chris".count("t"), 'city': "Seattle".count("t"), 'cake': "Chocolate".count("t")}
35+
print(stuff)
3536

3637
# Create sets s2, s3 and s4 containing numbers from 0-20, divisible 2, 3 and 4.
37-
s2 = set([1:20])
38-
s3 = set([1:20])
39-
s4 = set([1:20])
38+
s2 = set([x for x in range(0, 20) if x % 2 == 0])
39+
s3 = set([x for x in range(0, 20) if x % 3 == 0])
40+
s4 = set([x for x in range(0, 20) if x % 4 == 0])
4041

4142
# Display the sets.
43+
print(s2)
44+
print(s3)
45+
print(s4)
4246

4347
# Display if s3 is a subset of s2 (False)
48+
if s3.issubset(s2):
49+
print(True)
50+
else:
51+
print(False)
4452

4553
# and if s4 is a subset of s2 (True).
54+
if s4.issubset(s2):
55+
print(True)
56+
else:
57+
print(False)
4658

47-
# Create a set with the letters in ‘Python’ and add ‘i’ to the set.
59+
# Create a set with the letters in ‘Python’
60+
python = set(["p", "y", "t", "h", "o", "n"])
61+
62+
#add ‘i’ to the set.
63+
python.update(["i"])
64+
print(python)
4865

4966
# Create a frozenset with the letters in ‘marathon’
67+
marathon = frozenset(["m", "a", "r", "a", "t", "h", "o", "n"])
68+
print(marathon)
5069

51-
# display the union and intersection of the two sets.
70+
# display the union and intersection of the two sets.
71+
print(marathon.union(python))
72+
print(marathon.intersection(python))

0 commit comments

Comments
 (0)