Nile Project

i am getting a error on the Nile Project code line - name drivers is not defined

for driver in drivers:

driver_time = driver.speed * distance

price_for_driver = driver.salary * driver_time

if cheapest_driver is None:

  cheapest_driver = driver

  cheapest_driver_price = price_for_driver

elif price_for_driver < cheapest_driver_price:

  cheapest_driver = driver

  cheapest_driver_price = price_for_driver

return cheapest_driver_price, cheapest_driver

Check the following FAQ for details on code formatting and you can keep the whole thing together easily on the forums- Code Formatting FAQ.

Since there’s a return I assume this is a function (where’s the def statement?). Do you have a function parameter called drivers or is it called something else? Is drivers a name from outside the scope of the function, does the name match exactly?

A NameError occurs when there’s a reference to name that either doesn’t exist or at least isn’t within the current scope of the code where it was used.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.