main.py from Stack import Stack from Queue import Queue import random numbers = Stack() numbers.push(30) numbers.push(15) numbers.push(18) print(numbers.pop()) # should be 18 print(numbers.peek()) #...

I've written most of the code for this question,it just needs an if and for statement in the simulation.py and some edits in the main.


main.py from Stack import Stack from Queue import Queue import random numbers = Stack() numbers.push(30) numbers.push(15) numbers.push(18) print(numbers.pop()) # should be 18 print(numbers.peek()) # should be 15 def decimal_binary(decimal): remainders = Stack() while decimal > 0: rem = decimal % 2 decimal //= 2 remainders.push(rem) bin_equivalent = "" while not remainders.is_empty(): bin_equivalent += str(remainders.pop()) return bin_equivalent x = 16 print(decimal_binary(x)) def convert(number, base): remainders = Stack() digits = "0123456789ABCDEF" while number > 0: rem = number % base number //= base remainders.push(rem) converted = "" while not remainders.is_empty(): converted += str(digits[remainders.pop()]) return converted print(convert(15, 16)) ###################################### class Printer: def __init__(self, ppm): self.page_rate = ppm self.current_task = None self.time_remaining = 0 def tick(self): if self.current_task != None: self.time_remaining -= 1 if self.time_remaining <= 0: self.current_task = none def busy(self): if self.current_task != none: return true else: return false def start_next(self, new_task): self.current_task = new_task self.time_remaining = new_task.get_pages() * 60 / self.page_rate class task: def __init__(self, time): self.timestamp = time self.pages = random.randrange(1, 21) def get_stamp(self): return self.timestamp def get_pages(self): return self.pages def wait_time(self, current_time): return current_time - self.timestamp def simulation(num_seconds, pages_per_minutes): lab_printer = printer(pages_per_minutes) print_queue = queue() waiting_times = [] for current_second in range(num_seconds): if new_print_task(): task = task(current_second) print_queue.enqueue(task) if (not lab_printer.busy()) and (not print_queue.is_empty()): next_task = print_queue.dequeue() waiting_times.append(next_task.wait_time(current_second)) lab_printer.start_next(next_task) lab_printer.tick() average_wait = sum(waiting_times)/len(waiting_times) print("average wait: {:.2f} seconds. {} tasks remaining.".format(average_wait, print_queue.size())) def new_print_task(): num = random.randrange(1, 181) if num == 180: return true else: return false # run simulation print("run simulation with 5ppm") for i in range(10): simulation(3600, 5) print("\nrun simulation with 10ppm") for i in range(10): simulation(3600, 10) queue.py class queue: def __init__(self): self.items = [] def enqueue(self, item): self.items.insert(0,item) def dequeue(self): return self.items.pop() def is_empty(self): return self.items == [] def size(self): return len(self.items) stack.py class stack: def __init__(self): 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 is_empty(self): return self.items == [] def size(self): return len(self.items) 0:="" self.current_task="None" def="" busy(self):="" if="" self.current_task="" !="None:" return="" true="" else:="" return="" false="" def="" start_next(self,="" new_task):="" self.current_task="new_task" self.time_remaining="new_task.get_pages()" *="" 60="" self.page_rate="" class="" task:="" def="" __init__(self,="" time):="" self.timestamp="time" self.pages="random.randrange(1," 21)="" def="" get_stamp(self):="" return="" self.timestamp="" def="" get_pages(self):="" return="" self.pages="" def="" wait_time(self,="" current_time):="" return="" current_time="" -="" self.timestamp="" def="" simulation(num_seconds,="" pages_per_minutes):="" lab_printer="Printer(pages_per_minutes)" print_queue="Queue()" waiting_times="[]" for="" current_second="" in="" range(num_seconds):="" if="" new_print_task():="" task="Task(current_second)" print_queue.enqueue(task)="" if="" (not="" lab_printer.busy())="" and="" (not="" print_queue.is_empty()):="" next_task="print_queue.dequeue()" waiting_times.append(next_task.wait_time(current_second))="" lab_printer.start_next(next_task)="" lab_printer.tick()="" average_wait="sum(waiting_times)/len(waiting_times)" print("average="" wait:="" {:.2f}="" seconds.="" {}="" tasks="" remaining.".format(average_wait,="" print_queue.size()))="" def="" new_print_task():="" num="random.randrange(1," 181)="" if="" num="=" 180:="" return="" true="" else:="" return="" false="" #="" run="" simulation="" print("run="" simulation="" with="" 5ppm")="" for="" i="" in="" range(10):="" simulation(3600,="" 5)="" print("\nrun="" simulation="" with="" 10ppm")="" for="" i="" in="" range(10):="" simulation(3600,="" 10)="" queue.py="" class="" queue:="" def="" __init__(self):="" self.items="[]" def="" enqueue(self,="" item):="" self.items.insert(0,item)="" def="" dequeue(self):="" return="" self.items.pop()="" def="" is_empty(self):="" return="" self.items="=" []="" def="" size(self):="" return="" len(self.items)="" stack.py="" class="" stack:="" def="" __init__(self):="" 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="" is_empty(self):="" return="" self.items="=" []="" def="" size(self):="" return="">
May 15, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here