Question: in python 3 monsters1.txt monsters2.txt Queue.py could you please use the queue file Problem Description In this problem, monsters are arriving to a battlefield one-at-a-time.

in python 3

in python 3 monsters1.txt monsters2.txt Queue.py could you please use the queue

file Problem Description In this problem, monsters are arriving to a battlefield

monsters1.txt

one-at-a-time. The input for this problem will consist of of a text

monsters2.txt

file indicating the order in which the monsters arrive. Each line of

Queue.py

the file consists of a single monster's name. It might look like

this: Gezora Moguera Godzilla Mothra In general, the monster names could be

could you please use the queue file

Problem Description In this problem, monsters are arriving to a battlefield one-at-a-time. The input for this problem will consist of of a text file indicating the order in which the monsters arrive. Each line of the file consists of a single monster's name. It might look like this: Gezora Moguera Godzilla Mothra In general, the monster names could be anything, but two names are of special significance: Godzilla and Mothra. All other names are for space monsters. A name could occur more than once, and the names Godzilla and Mothra in particular will very likely occur many times. To simulate the battle, your program should keep track of the order in which the space monsters arrive. Whenever either Godzilla or Mothra arrives, they will defeat whichever space monster is currently first in line. If Godzilla or Mothra arrive when there are no space monsters waiting, nothing happens for now. Two end results of this battle are possible: The space monsters lose if all of the space monsters are defeated. In this case, your program should print out the names of all of the space monsters that were defeated by each of Godzilla and Mothra The space monsters win. This happens if there is at least one space monster who is not defeated by Godzilla or Mothra In this case, the program should print out the name of the space monster who is currently first in line Implementation This is a problem where a Queue data structure can be very useful A simple implementation of the Queue ADT is provided on the course website. Your program must make effective use of the Queue ADT as part of your approach to solving this problem. Sample Output Some sample input files are provided on the course website. For monsters1.txt, your output might look like this: The space monsters were beaten! Godzilla defeated : Moguera Mothra defeated : Gezora Varan Alternatively, for monsters2.txt, your output might look like this: Oh no! The space monsters won thanks to Mechagodzilla We may test your program win inputs beyond just those given here. What to Hand In A file named a5q2.py with your solution to this problem. It must import the Queue ADT. It is NOT required to hand in the provided Queue file. Be sure to include your name. NSID. student number, course number and instructor name at the top of all documents. Evaluation . 4 marks: The overall outcome is correctly computed (at most 1 mark if a Queue is not used effectively) . 3 marks: The list of defeated monsters is correctly computed for both Godzilla and Mothra 1 mark: The correct space monster is reported when the space monsters win 1 15 Gezona Moguera Mothra Godzilla Varan Mothra 4 Wow 6 1 Hedorah Godzilla Baragon Mothra Mechagodzilla 4 18 Eclass Queue (object): 19 20 def __init__(self): 21 25 Purpose creates an empty queue Return an empty queue 24 I 25 10 26 27 self data = listo 28 29 def is empty(self): 50 AT AL 51 52 Purpose checks if the given queue has no data in it Return: True if the queve has no data, or false otherwise 34 11 12 36 B return len(self data) -- 0 37 39 def..size(self) 40 A 41 22 Purpose returns the number of data values in the given queue Return: The number of data values in the queue 44 1 45 1111 46 return len(self.data) 48 defengueue self.value 51 52 53 54 55 56 57 58 59 Purpose adds the given data value to the given queue Pre-conditions: queue: a queve created by create value: data to be added Post-condition the value is added to the queue Return: (none) 60 50 52 54 55 Purpose adds the given data value to the given queue Pre-conditions: queue: a queue created by create() value: data to be added Post-condition: the value is added to the queue Return: (none) 57 58 59 61 self data.append(value) 62 63 def dequeue (self): -D-D 65 de AB 68 BnBBBBBB89a,,, m Purpose removes and returns a data value from the given queue Pre-conditions: queue: a queue created by create() Post-condition: the first value is removed from the queue Return: the first value in the queue 73 74 return self.data.pop(0) 76 ka-a-D-D def peek(self): 78 81 82 83 Purpose returns the value from the front of given queue without removing it Pre-conditions: queue: a queue created by create() Post-condition: None Return: the value at the front of the queue 84 85 86 88 89 E return self.data[0] 90

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!