This repository has been archived by the owner on Aug 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHW7.py
52 lines (39 loc) · 1.77 KB
/
HW7.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
# Details:
# Return to your first homework assignments, when you described your favorite song.
# Refactor that code so all the variables are held as dictionary keys and value.
# Then refactor your print statements so that it's a single loop that passes through each item in the dictionary and prints out it's key and then it's value.
# Extra Credit:
# Create a function that allows someone to guess the value of any key in the dictionary, and find out if they were right or wrong.
# This function should accept two parameters: Key and Value.
# If the key exists in the dictionary and that value is the correct value, then the function should return true. In all other cases, it should return false.
#Homework #7: Dictionares and Sets
song = {"genre":"progressive rock", "artist":"pink floyd", "album":" wish you were here",
"year":"1975",}
def printSongMD():
print("\n *** Song Info ***\n")
for key in song:
print(key, ":", song[key])
print("\n *** End ***\n")
def askQuestion():
key = input("\nGreat, let\'s start the game, guess the key?\n")
value = input("\nWhat you think is the value of " + key + "?\n")
if key and value:
key = key.lower()
value = value.lower()
# value = value.capitalize()
if key in song and song[key].lower() == value:
return True
return False
def startGuessingGame():
if askQuestion():
print("Bingo! You guessed it right...")
else:
print("Oops... You missed!")
repeat = input("\nWanna try again? Say 'yes' to continue or say 'no'.\n")
if repeat.lower() == "yes":
startGuessingGame()
else:
print("\nSee you again!")
printSongMD()
print("Starting game....\n")
startGuessingGame()