51 lines
1.5 KiB
Python
51 lines
1.5 KiB
Python
from random import randrange
|
|
|
|
songs = [("You hear the door slam. And realize there's nowhere left to", "run"),
|
|
("Oh, I wanna dance with somebody. I wanna feel the", "heat"),
|
|
("There's a fire starting in my heart. Reaching a fever", "pitch"),
|
|
("Hey, I just met you and this is crazy. But here's my", "number"),
|
|
("'Cause baby, you're a firework. Come on, show 'em what you're", "worth")]
|
|
|
|
# Om jeg tar inn songs som parameter vil ikke pop_random_songs kunne fjerne noe fra lista.
|
|
# Her velger jeg aktivt å ikke ta et argument inn med tanke på oppgave B
|
|
def pop_random_songs():
|
|
songIndex = randrange(len(songs))
|
|
song = songs[songIndex]
|
|
del songs[songIndex]
|
|
return song
|
|
|
|
def continueGuessing():
|
|
while True:
|
|
try:
|
|
answer = input('Do you want to go again? [y/n] ')
|
|
assert answer in ['y', 'Y', 'n', 'N']
|
|
return answer in ['y', 'Y']
|
|
except AssertionError:
|
|
pass
|
|
|
|
def song_contest():
|
|
currentSong = pop_random_songs()
|
|
while True:
|
|
|
|
print('The lyrics are:')
|
|
print(currentSong[0])
|
|
answer = input('What\'s the next word? ')
|
|
|
|
if answer.lower() == currentSong[1].lower():
|
|
print(f'Correct!')
|
|
if len(songs) == 0:
|
|
print('You did it! You remembered all the objects')
|
|
exit(0)
|
|
elif continueGuessing():
|
|
currentSong = pop_random_songs()
|
|
else:
|
|
print('Welcome back later :D')
|
|
exit(0)
|
|
|
|
else:
|
|
print('Wrong guess. Try again.')
|
|
|
|
|
|
song_contest()
|
|
# for _ in range(5):
|
|
# print(pop_random_songs()) |