@Brawn/

Dictionaries

Python

No description

fork
loading
Files
  • main.py
main.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
dictionaryName = {
	"keyNameOne" : "stringValue",
    "keyNameTwo" : [2, 1, 0],
    "keyNameThree" : 3.0,
    "keyNameFour" : 4,
    "keyNameFive" : 5,
    "keyNameSix" : 6
    }

# Adding a key and value

#dictionaryName["keyNameZero"] = 0

#dictionaryName["keyNameZero"] = "zero"

# Removing element

#dictionaryName.pop("keyNameZero")  

# Deleating all data

#dictionaryName.clear()

# PRINTING DICTIONARY

#print(dictionaryName.get("keyNameTwo"))

#OR  (works the same)

#print(dictionaryName["keyNameZero"])

#print(dictionaryName)

"""
#               DICTIONARY PROBLEMS

studentOne = {
	"name" : "Lloyd",
	"homework" : [90.0, 97.0, 75.0, 92.0],
	"quizzes": [88.0, 40.0, 94.0],
	"tests" : [75.0, 90.0]
}


studentTwo = {
	"name" : "Alice",
	"homework" : [100.0, 92.0, 98.0, 100.0],
	"quizzes": [82.0, 83.0, 91.0],
	"tests" : [89.0, 97.0]
}


studentThree = {
	"name" : "Brad",
	"homework" : [0.0, 87.0, 75.0, 22.0],
	"quizzes": [0.0, 75.0, 78.0],
	"tests" : [100.0, 100.0]
}

def average(score):
	return sum(score)/len(score)

#print(average(studentOne.get("homework")))

def student_average(student):
	homework = (average(student["homework"]) *.3)
	quizzes = (average(student["quizzes"]) *.4)
	tests = (average(student["tests"]) *.3)
	return sum([homework, quizzes, tests])

Lloyd = student_average(studentOne)
Alice = student_average(studentTwo)
Brad = student_average(studentThree)

def get_letter_grade(student):
	if student >= 90:
		return "A"
	elif student >= 80:
		return "B"
	elif student >= 70:
		return "C"
	elif student >= 60:
		return "D"
	else:
		return "F"

print(get_letter_grade(Lloyd))


#         Dictionary Quiz Practice Problems

zainab = {
        "name" : "Zainab",
        "Watched the game?" : "yes", #watched the super bowl
        "Team routed for?" : "Rams" #routed for the Eagles
        }
mekyes = {
        "name" : "Mekyes",
        "Watched the game?" : "yes", 
        "Team routed for?" : "Patriots" 
        }
azeez = {
        "name" : "Azeez",
        "Watched the game?" : "no", 
        "Team routed for?" : "Patriots" 
        }
sportsFans = [zainab, mekyes, azeez]
for item in sportsFans:
    if item["Watched the game?"] == "yes":
    #if the value to the key "Watched the game?" is "yes"...
        if item["Team routed for?"] == "Patriots":
        #if the value to "Team routed for?" was "Patriots"...
            print("{} watched the Super Bowl and was happy the {} won.".format(item["name"], item["Team routed for?"]))
            #print the name of the person and the team they rooted for.
        else:
            print("{} watched the Super Bowl and was sad the {} lost.".format(item["name"], item["Team routed for?"]))
            #print the name of the person and the team they rooted for.
    else:
        print("{} did not watch the Super Bowl.".format(item["name"]))
        #print the name of the person.


def pyth(a,b):
	c = (a**2)+(b**2)
	return c


def triangleFun(a,b):
	mathDictionary = {
		"base" : a,
		"height" : b,
		"hypotenuse" : -1
	}
	mathDictionary["hypotenuse"] = pyth(a,b)
	mathDictionary["area"] = 0.5 * a * b
	mathDictionary["perimeter"] = a+b+mathDictionary["hypotenuse"]
	return mathDictionary

"""

pikachu = {
	"name" : "Pikachu",
	"type" : "electric",
	"HP" : 40,
	"Tackle" : 6,
	"Scratch" : 6,
	"Thunder Shock" : 14
}

charmander = {
	"name" : "Charmander",
	"type" : "fire",
	"HP" : 30,
	"Tackle" : 6,
	"Scratch" : 9,
	"Ember" : 12
}

print("Ash ran into a wild PokeMon.")
print("Wild PokeMon is {}.".format(charmander["name"]))

print("Ash sends out {}.".format(pikachu["name"]))

catchable = False

while catchable == False:
	print("{} uses Ember.".format(charmander["name"]))
	pikachu["HP"] = pikachu["HP"] - charmander["Ember"]
	print("{} uses Thunder Shock.".format(pikachu["name"]))
	charmander["HP"] = charmander["HP"] - pikachu["Thunder Shock"]
	print("Pikachu's health is {}.".format(pikachu["HP"]))
	print("Charmander's health is {}.".format(charmander["HP"]))
	if charmander["HP"] < 7:
		catchable = True

print("Ash uses a Pokeball and catches {}!".format(charmander["name"]))