Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Modify the hot potato simulation to allow for a randomly choosen counting value

ID: 3576974 • Letter: M

Question

Modify the hot potato simulation to allow for a randomly choosen counting value so that each pass is not predictable from the previus one.

use this two file:

==================================Hot potato==========================================

from qu import Queue

def hotPotato(namelist, num):
simqueue = Queue()
for name in namelist:
simqueue.enqueue(name)
while simqueue.size() > 1:
for i in range(num):
simqueue.enqueue(simqueue.dequeue())
simqueue.dequeue()
return simqueue.dequeue()

def main():
names = ["Bob", "Sally", "Susan", "Bill", "Mary"]
num = 4
print(hotPotato(names, num))
  
main()

=================================Stack===================================

class Stack:
def __init__(self):
self.items = []

def isEmpty(self):
return self.items == []

def push(self, item):
self.items.append(item)

def pop(self):
return self.items.pop()

def peek(self):
return self.items[len(self.items)-1]

def size(self):
return len(self.items)
----------------------------------------------------------------------

make sure you modify them not create new one. Python program language

Explanation / Answer

from queue import Queue
from random import randint
def hotPotato(namelist, num):
    simqueue = Queue()
    for name in namelist:
        simqueue.put(name)
    while simqueue.qsize() > 1:
        for i in range(num):
            simqueue.put(simqueue.get())
        simqueue.get()
    return simqueue.get()

def main():
    names = ["Bob", "Sally", "Susan", "Bill", "Mary"]
    num = randint(1,5)
    print(hotPotato(names, num))

main()

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote