Calculate and returns the new number of items in a queue

Assignment Help Python Programming
Reference no: EM132356141

Question

You are having trouble figuring out how to structure my code.

Directions:

calc_waiting(arrive, depart, curr_waiting) - Calculates and returns the new number of items in a queue based on the given arrivals, departures, and items already waiting in the queue. This function will not return a negative value. Instead, any computed negative value will be replaced with 0 before it is returned. HINT: Check out the built-in max function. Note that this function does not output (print) the computed value!

run_sim(lanes, capacity, block_lanes, block_time, rnd_gen) - Executes the simulation, calculating the minute by minute volumes of vehicles arriving, departing, and waiting in the backup. The arguments represent the total number of lanes, the maximum traffic capacity (as provided by the user), the number of blocked lanes, the duration of the lane blockage, and the RandomArrivals object that will be used to generate the number of vehicles arriving at each minute of the simulation..

The state of the simulation, represented by the number of arrivals, departures, and waiting vehicles is output to the console with each minute count. The simulation stops after outputting the line where the number of waiting (backed-up) vehicles reaches zero. This function will implement the design illustrated in Figure 2 above, including printing the table header and footer. The total width of the tabular output from this function shall not exceed a width of 75 character columns on a terminal/command prompt display.

print_welcome() - This function neatly prints a welcome message, as described earlier in this document. Your welcome message must include your name, unity ID, and lab section number. The output generated by this function will not exceed a width of 75 character columns on a terminal/command prompt display. The length of the output will not exceed a length of 20 lines.

print_goodbye() - This function neatly prints a "goodbye" message to the user, as described earlier in this document. The output generated by this function will not exceed a width of 75 character columns on a terminal/command prompt display. The length of the output will not exceed a length of 5 lines.
main() - This function will contain your main program loop as described by the flowchart in Figure 4. The execution of this function must be controlled by the if __name__ == '__main__': statement provided in the course template.

Existing code:

def print_welcome():

"Welcome! My name is Joelle Dvorak, my unity ID is jmdvorak, and my lab section number 204. This program is designed to simulate traffic flow. Afterwards, the program then displays the simulation results in a table format."

def print_goodbye():

"Thanks for using the program. Exiting program now. You will be returned to the -----"

def calc_waiting(arrive, depart, curr_wait):

"""This function will prompt the user to input an integer value.

The function will then convert the input to an int value and return that

value to the caller.

Args:

arrive (int): Number of vehicles arriving in lane i. Value to be multiplied by 2.

depart (int): Number of vehicles departing in lane i. Value to be subtracted from arrive and curr_wait together

curr_wait (int): Number of vehicles waiting. Value to be added to arrive

Returns:

The value of num

"""

depart = con.MAX_CAPACITY + total_lanes

num = 2 * arrive + curr_wait - depart

return num

def sim_line(time, arrive, depart, curr_wait) :

"""This function helps create the tabular formatted output.

Args:

time (int): Amount of time in one minute increments

normal (int): Number of normal traffic flow

capacity (int): Maximum amount of cars that can flow on one lane at a time

block_time (int): Number of vehicles waiting

Returns:

Tabular format for run_sim

"""

return '{0:^10d}{1:^10d}{2:^10d}{3:^10d}' .format(time, arrive, depart, curr_wait)

def run_sim(lanes, capacity, block_lanes, block_time, rnd_gen) :

"""This function will prompt the user to input an integer value.

The function will then convert the input to an int value and return that

value to the caller.

Args:

normal (int): Number of vehicles that normally flow through a single lane

capacity (int): Maximum amount of vehicles that can be on a single lane

block_time (int): Number of vehicles waiting

Returns:

Raw data output in the format of a tabular table.

"""

lanes = inp.get_int("Enter the total number of lanes present: ")

capacity = inp.get_int("What is the maximum capacity of one lane? ")

block_lanes = inp.get_int("Enter the number of lanes that will be blocked during the simulation: ")

inp.get_string("Enter the average normal traffic flow rate of one lane: ")

time = 0

curr_wait = 0

while block_time > 0 :

time += 1

arrive = 2 * normal

leave = capacity

curr_wait = calc_waiting(lanes, capacity, block_lanes, block_time, rnd_gen)

if time > block_time:

curr_wait = curr_wait - capacity

leave = 2 * capacity

print(sim_line(time, arrive, leave, curr_wait))

def main():

print print_welcome

if exec_sim = true:

elif exec_sim = false:

print print_goodbye

var =

val =

if(curr_wait < 0):

ans = inp.get_string("Would you like to run another simulation? ")

elif ans = yes:

elif ans = no:

return

print print_goodbye

Reference no: EM132356141

Questions Cloud

Allow the user to output all vehicle inventory to text file : Need an automobile class that will be used by a dealership as a vehicle inventory program. The following attributes should be present in your automobile class.
Define interrelationship of ethics and social responsibility : Determine the role of stakeholder interests, the interrelationship of ethics and social responsibility, and the role of corporate governance in ethics.
Academically reviewed articles on team leadership : As a group, review at least four academically reviewed articles on Team Leadership. Develop power presentation based on the articles.
Design and implement a program that prints the number of odd : Design and implement a program that prints the number of odd, even, and 0 digits in an integer value that it reads from the keyboard.
Calculate and returns the new number of items in a queue : Calculates and returns the new number of items in a queue based on the given arrivals, departures, and items already waiting in the queue.
Developing and implementing a code of ethics : Review Table 8-4 "Developing and Implementing a Code of Ethics" (Chapter 8). Outline a plan for implementing a training and development program in your current.
Describe in-groups and in-group favoritism : Describe in-groups and in-group favoritism. How can manager control negative effects of in-group formation? What are common characteristics of effective team.
Convert to a group of tables in first normal form : Normalization Exercise 1: For each of the following tables - Convert to a group of tables in first normal form. Show the primary key of each table
Determine the fundamental ways to prevent the scandals : Determine the fundamental ways in which the NCAA's ethics program failed to prevent the scandals at Penn State, Ohio State, and the University of Alaska.

Reviews

Write a Review

Python Programming Questions & Answers

  Write a python program to implement the diff command

Without using the system() function to call any bash commands, write a python program that will implement a simple version of the diff command.

  Write a program for checking a circle

Write a program for checking a circle program must either print "is a circle: YES" or "is a circle: NO", appropriately.

  Prepare a python program

Prepare a Python program which evaluates how many stuck numbers there are in a range of integers. The range will be input as two command-line arguments.

  Python atm program to enter account number

Write a simple Python ATM program. Ask user to enter their account number, and print their initail balance. (Just make one up). Ask them if they wish to make deposit or withdrawal.

  Python function to calculate two roots

Write a Python function main() to calculate two roots. You must input a,b and c from keyboard, and then print two roots. Suppose the discriminant D= b2-4ac is positive.

  Design program that asks user to enter amount in python

IN Python Design a program that asks the user to enter the amount that he or she has budget in a month. A loop should then prompt the user to enter his or her expenses for the month.

  Write python program which imports three dictionaries

Write a Python program called hours.py which imports three dictionaries, and uses the data in them to calculate how many hours each person has spent in the lab.

  Write python program to create factors of numbers

Write down a python program which takes two numbers and creates the factors of both numbers and displays the greatest common factor.

  Email spam filter

Analyze the emails and predict whether the mail is a spam or not a spam - Create a training file and copy the text of several mails and spams in to it And create a test set identical to the training set but with different examples.

  Improve the readability and structural design of the code

Improve the readability and structural design of the code by improving the function names, variables, and loops, as well as whitespace. Move functions close to related functions or blocks of code related to your organised code.

  Create a simple and responsive gui

Please use primarily PHP or Python to solve the exercise and create a simple and responsive GUI, using HTML, CSS and JavaScript.Do not use a database.

  The program is to print the time

The program is to print the time in seconds that the iterative version takes, the time in seconds that the recursive version takes, and the difference between the times.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd