Question: Hello, I have a Python3 project that I'm a little stuck on. I'm working with stacks and queues . I'll post my assignment instructions and

Hello, I have a Python3 project that I'm a little stuck on. I'm working with stacks and queues. I'll post my assignment instructions and my code below and then explain my problem after that.

Hello, I have a Python3 project that I'm a little stuck on.I'm working with stacks and queues. I'll post my assignment instructions andmy code below and then explain my problem after that. Hints and

Hints and Tips:

make a form with two text areas and one submit.

make a class that contains the name and number, then make queues and stacks of that class. (Of course you can use a list instead of the class)

Plan:

start with a form that reads and prints the data

put the servers in a stack and print them

put the customers in a queue and print them

work on the top/first

Example Logic For Splitting:

# create a server or customer inputbox = """ken 23 keith 43 karl 14 kevin 66""" print (inputbox) #split the inputbox into a list of separate items items = inputbox.split(" ") for item in items: print ("Item is [{}]".format(item)) # convert each item to a pair of string (name, value) = item.split() # split on space value = int(value) # turn value into an integer # I use value + 1 to show that it's an integer print (" The name is [{}] and the value+1 is [{}] ".format(name, value+1))

MY CODE BELOW:

form.html

Input server names here: Input customer names here:

scriptname.py

#!/usr/local/bin/python3 import cgi, cgitb, random cgitb.enable() print("Content-type: text/html ") def schedule(server,customer): #server list will acts as stack #and customer list will act as queue #loop will Continue unitil both the customer and the sever are filled while len(server) > 0 and len(customer) > 0: server_name , server_count = server[-1][0],server[-1][1] customer_name , customer_count = customer[0][0],customer[0][1] #if count of both server and customer are equal if server_count == customer_count: #pop from server and dequeue from customer server.pop() customer.pop(0) #print(f"{server_name} gives service to {customer_name}") #if server count is more than customer requires the service elif server_count > customer_count: #reduce the count of server server[-1][1] = server_count-customer_count #pop the customer out(indicating his task is completed) customer.pop(0) #print(f"{server_name} gives service to {customer_name}") elif server_count 

So when inputting random names into both my text areas, I get an internal server error. When executing within my python code, I get this error:

server_textbox = form.getvalue('server_input') s = server_textbox.split(" ") AttributeError: 'NoneType' object has no attribute 'split'

I'm assuming the same will happen for c and customer_textbox. I'm wondering how to fix this error.

Another problem I can see that might happen is I'm trying to assign random integer numbers as ids to each customer and server and then splitting them but I'm not certain how to append the textboxes with said ids. I feel like that will have an error there too and was wondering how to input numbers next to names when submitting after the textbox. I feel like my function works fine but if any issues are spotted please correct those too according to the instructions. Thank you!

Servers and customers Servers are stored in a stack, where the first server in the textarea is the the last server used. It is a requirement that you use a stack of servers. Customers are stored in a queue, where the first customer in the textarea is the first customer used. It is a requirement that you use a queue of customers. Each server and customer has a Name and a Number associated with it. The Name is used for printing and the Number is the amount the server can serve or the customer needs served. Each will have a separate text area. "load" the first server (at the bottom) and the first customer (at the top): - If they are the same, report that and remove both from their respective areas and move on to the next two. - If the server can serve more than the customer requires, the server completely serves the customer and reduces the Number on that server by the amount served. Remove the customer and move on to the next customer. - If the customer needs more served than the server can serve, the customer completely uses up the server and reduces the Number on that customer by the amount served. Remove the server and move on to the next server. When to end (the loop condition) - If all the servers are done serving, report that there are no more servers. - If all the customers are done being served, report that there are no more customers

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 General Management Questions!