Skip to content

Commit 24422e3

Browse files
committed
Rename folders and finished chapter 5
1 parent 81c4cf2 commit 24422e3

28 files changed

+85
-0
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

05-dict/birthdays.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
birthdays = {'Alice': 'Apr 1', 'Bob': 'Dec 12', 'Carol': 'Mar 4'}
2+
3+
while True:
4+
print('Enter a name: (blank to quit)')
5+
name = input()
6+
if name == '':
7+
break
8+
9+
if name in birthdays:
10+
print(birthdays[name] + ' is the birthday of ' + name)
11+
else:
12+
print('I do not have birthday information for ' + name)
13+
print('What is their birthday?')
14+
bday = input()
15+
birthdays[name] = bday
16+
print('Birthday database updated.')

05-dict/characterCount.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
message = 'It was a bright cold day in April, and the clocks were striking thirteen.'
2+
count = {}
3+
4+
for character in message:
5+
#count.setdefault(character, 0)
6+
count[character] = count.get(character, 0) + 1
7+
8+
print(count)

05-dict/dragonLoot.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
def displayInventory(inventory):
2+
print("Inventory:")
3+
item_total = 0
4+
for k, v in inventory.items():
5+
print(str(v) + '\t' + k)
6+
item_total += v
7+
print('-'*40)
8+
print("Total number of items: " + str(item_total))
9+
10+
def addToInventory(inventory, addedItems):
11+
for item in addedItems:
12+
inventory[item] = inventory.get(item, 0) + 1
13+
return inventory
14+
15+
inv = {'gold coin': 42, 'rope': 1}
16+
dragonLoot = ['gold coin', 'dagger', 'gold coin', 'gold coin', 'ruby']
17+
inv = addToInventory(inv, dragonLoot)
18+
displayInventory(inv)

05-dict/inventory.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# inventory.py
2+
stuff = {'rope': 1, 'torch': 6, 'gold coin': 42, 'dagger': 1, 'arrow': 12}
3+
4+
def display_inventory(inventory):
5+
print("Inventory:")
6+
item_total = 0
7+
for k, v in inventory.items():
8+
print(str(v) + '\t' + k)
9+
item_total += v
10+
print('-'*40)
11+
print("Total number of items: " + str(item_total))
12+
13+
display_inventory(stuff)

05-dict/prettyCharacterCount.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import pprint
2+
message = 'It was a bright cold day in April, and the clocks were striking thirteen.'
3+
count = {}
4+
5+
for character in message:
6+
#count.setdefault(character, 0)
7+
count[character] = count.get(character, 0) + 1
8+
9+
pprint.pprint(count)

05-dict/ticTacToe.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
theBoard = {'top-L': ' ', 'top-M': ' ', 'top-R': ' ',
2+
'mid-L': ' ', 'mid-M': ' ', 'mid-R': ' ',
3+
'low-L': ' ', 'low-M': ' ', 'low-R': ' '}
4+
def printBoard(board):
5+
print(board['top-L'] + '|' + board['top-M'] + '|' + board['top-R'])
6+
print('-+-+-')
7+
print(board['mid-L'] + '|' + board['mid-M'] + '|' + board['mid-R'])
8+
print('-+-+-')
9+
print(board['low-L'] + '|' + board['low-M'] + '|' + board['low-R'])
10+
11+
turn = 'X'
12+
for i in range(9):
13+
printBoard(theBoard)
14+
print('Turn for ' + turn + '. Move on which space?')
15+
move = input()
16+
theBoard[move] = turn
17+
if turn == 'X':
18+
turn = 'O'
19+
else:
20+
turn = 'X'
21+
printBoard(theBoard)

0 commit comments

Comments
 (0)