-
Notifications
You must be signed in to change notification settings - Fork 0
/
day9_dictionaries.py
101 lines (91 loc) · 2.52 KB
/
day9_dictionaries.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# DAY 9: Dictionaries, Nesting
# CHALLENGES & NOTES
# dictionaries tag and group together related pieces of information
# comprised of a key and a value
first_dic = {
"key": "value", "mike": "dick", "dog": "bounty hunter", "age": 28,
"something_new": "new_value",
} # this is the preferred format
# print(first_dic["dog"])
# print(first_dic)
# loop through a dict:
# for key in first_dic:
# print(f"{key} : {first_dic[key]}")
# grading program
student_scores = {
"Harry": 81,
"Ron": 78,
"Hermione": 99,
"Draco": 74,
"Neville": 62,
}
student_grades = {}
for student in student_scores:
if student_scores[student] < 70:
student_grades[student] = "Failure"
elif student_scores[student] < 80:
student_grades[student] = "Average -"
elif student_scores[student] < 90:
student_grades[student] = "Average +"
else:
student_grades[student] = "Actually decent"
# print(f"{student}: {student_grades[student]}")
# Nesting: you guessed it
# test = {
# "key": ["list", "of", "things"],
# "key2": {"value_key": "value_value"}
# }
# travel_log = {
# "France": {"cities_visited": ["Paris", "Lille", "Dijon"]},
# "Germany": {"cities_avoided": ["berlin", "Hamburg", "Stuttgart"], "germans_scoffed_at": 43},
# }
# Nesting Challenge
travel_log = [
{
"country": "France",
"visits": 12,
"cities": ["Paris", "Lille", "Dijon"]
},
{
"country": "Germany",
"visits": 5,
"cities": ["Berlin", "Hamburg", "Stuttgart"]
},
]
# travel_log += 5
# def add_new_country(state, tours, cities):
# new_entry = {
# "country": state,
# "visits": tours,
# "cities": cities,
# }
# travel_log.append(new_entry)
#
#
# add_new_country("Russia", 2, ["Moscow", "Saint Petersburg"])
# print(travel_log)
# PROJECT: Silent Auction
import os
import asciiArt
others = True
bids = {}
print(asciiArt.homer)
print('"Welcome to the silent auction" - Homer')
while others:
name = input("What is your name? ")
bid = float(input("What is your bid? "))
more_ppl = input("Any participants after you? [y/n]: ").lower()
if more_ppl != "y":
others = False
bids[name] = bid
os.system('cls' if os.name == 'nt' else 'clear')
winning_bid = 0
winner = ""
for name in bids:
if bids[name] > winning_bid:
winning_bid = bids[name]
winner = name
elif bids[name] == winning_bid:
winner += f" & {name}"
print("The results are in...")
print(f"The winner is {winner} with a bid of {winning_bid}")