Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Python Expert

Create a ride share simulator assignment. In this particular function, I am trying to create a list of the drivers in a Driver Class that are currently listed as idle. Since they are idle, I can then match them up with an awaiting rider. The assignment dictates that I must find the closest driver to the rider, so this is my code:

def request_driver(self, rider):
"""Return a driver for the rider, or None if no driver is available.

Add the rider to the waiting list if there is no available driver.

@type self: Dispatcher
@type rider: Rider
@rtype: Driver | None
"""
availdriver = []
for driver in self.driverlist:
if driver[1] == True:
availdriver.append(driver[0])

if len(availdriver) == 0:
return None
self.waitlist.append(rider)
elif len(availdriver) == 1:
return availdriver[0]
else:
nearest = availdriver[0]
for i in range(len(availdriver)):
if availdriver[i].get_travel_time(rider.origin) nearest = availdriver[i]
return nearest

 

(this text box isn't amenable to tabbing so pretend it's properly indented)

So because I am saving instances of a class into a list, when I read out the list, they are bring read as string objects. do you know a way around this?

 

This is the code responsible for producing driverlist

def request_rider(self, driver):
"""Return a rider for the driver, or None if no rider is available.

If this is a new driver, register the driver for future rider requests.

@type self: Dispatcher
@type driver: Driver
@rtype: Rider | None
"""
if driver.id not in self.driverlist:
self.driverlist.append([driver.id, driver.is_idle])
if len(self.waitlist) == 0:
return None
else:return self.waitlist.pop(0)

 

this is a first year computer class so if I used any advanced functions it would look very fishy.

 

Python, Programming

  • Category:- Python
  • Reference No.:- M91697265

Have any Question?


Related Questions in Python

Part i the assignment filesone of the most important

Part I: The Assignment Files One of the most important outcomes of this assignment is that you understand the importance of testing. This assignment will follow an iterative development cycle. That means you will write a ...

Assignment1 utilising python 3 build the following

Assignment 1. Utilising Python 3 Build the following regression models: - Decision Tree - Gradient Boosted Tree - Linear regression 2. Select a dataset (other than the example dataset given in section 3) and apply the De ...

Lab assignment -background - we have discussed in detail

Lab Assignment - Background - We have discussed, in detail, the function of Stacks and Queues and how they are specifically implemented in Python. To get a better understanding of the utility of these data structures, we ...

Question why is software configuration management

Question : Why is software configuration management considered an umbrella activity in software engineering? Please include examples and supporting discussion. The response must be typed, single spaced, must be in times ...

Question write a python program with a graphical user

Question: Write a python program with a graphical user interface that will allow a user to create a custom pizza which they wish to order. At minimum, the user should be able to choose the size of the pizza, the type of ...

Question a software company sells a package that retails

Question : A software company sells a package that retails for $99. Quantity discounts are given according to the following table: Quantity Discount 10 - 19 20% 20 - 49 30% 50 - 99 40% 100 or more 50% Write a program usi ...

Sieve of eratosthenes in pythonthe goal is to find all the

Sieve of Eratosthenes (in Python) The goal is to find all the prime numbers less than or equal to some natural number maxn. We have a list that tells us if any of the numbers 0..maxn are "marked". It can be an array of b ...

Architecture and system integrationcase study queensland

Architecture and System Integration Case Study: Queensland Health - eHealth Investment Strategy After evaluating various platforms, Queensland Health finally decided to adopt a Service Oriented Architecture (SOA) for its ...

Environment setupthe first mini project will be based on

Environment Setup The first mini project will be based on Ladder Logic programming. We will be using Schneider Electric's IDE called SoMachine Basic to do the programming. The latest ver- sion of SoMachine Basic for Wind ...

Quesiton write a python script that counts occurrences of

Quesiton: Write a python script that counts occurrences of words in a file. • The script expects two command-line arguments: the name of an input file and a threshold (an integer). Here is an example of how to run the sc ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As