class FunnyJukeBox:
def __init__(self):
self.container =
def isEmpty(self):
return self.size() == 0
def push(self, item):
self.container.append(item)
def peek(self):
if self.size()>0 :
return self.container[-1]
else :
return None
def pop(self):
return self.container.pop()
def size(self):
return len(self.container)
class PlaySong:
def __init__(self):
self.container =
def isEmpty(self):
return self.size() == 0
def push(self, item):
self.container.append(item)
# return first item
def peek(self):
if self.size()>0 :
return self.container[-1]
else :
return None
def pop(self):
return self.container.pop()
def size(self):
return len(self.container)
s = FunnyJukeBox()
s.push('Just the way you are')
s.push('I believe I can Fly')
s.push('Faded')
s.push('Firework')
s.push('One Call away')
p = PlaySong()
import random
songnum = [1,2,3,4,5,6,7,8,9,10]
counter = 0
Song = s.peek()
while counter <=5:
counter = counter + 1
songsnum = random.choice(songnum)
if songsnum <= 8:
print("Random Number", songsnum)
p.push(Song)
s.pop()
if counter == 5:
print("Have a nice day!", "\n")
break
else:
print("Random Number", songsnum)
print("Have a nice day!", "\n")
break
if p.size() == 0:
print("")
elif p.size() != 0:
print("The following song(s) we have played are:")
newCounter = p.size()
if songsnum <= 8:
while newCounter <= 5:
newCounter = newCounter - 1
print(p.peek())
p.pop()
if newCounter == 0:
break
else:
while newCounter <= 5:
newCounter = newCounter - 1
print(p.peek())
p.pop()
if newCounter == 0:
break
Result:
Random Number 5
Random Number 3
Random Number 7
Random Number 7
Random Number 5
Have a nice day!
The following song(s) we have played are:
One Call away <
One Call away <
One Call away < My main problem
One Call away <
One Call away <
I dont want to repeat the results of 'One Call away'. I only want to print it once, pop it, then peek the next item in the stack. I dont understand what is going on.