My Result does not show the time in rounded, the function created estimated_time_rounded seems doing nothing in this result, is there anything I miss, I tried to remove that function and still the result comes

def trip_planner_welcome(name):

print("Welcome to tripplanner v1.0 " + name)

def destination_setup(origin, destination, estimated_time, mode_of_transport=“Car”):

print("Your trip starts off in " +origin)

print("And you are traveling to " +destination)

print("You will be traveling by "+ mode_of_transport)

print(“It will take approximately " + str(estimated_time) + " hours”)

def estimated_time_rounded(estimated_time):

return rounded_time

rounded_time = round(estimated_time)

trip_planner_welcome(“Abdul !”)

destination_setup(“New Delhi”, “Hariyana”, 5.65)

Hello,
your function isn’t working as expected because you are returning rounded_time before assigning it to round(estimated_time).

Put the return statement below the assignment statement and it should work.

2 Likes

+1 to @microrunner33748 for pointing out your return statement.

It may also be good to note though that you don’t ever call estimated_time_rounded. If you were to call it, you’d actually receive an UnboundLocaleError due to rounded_time not being defined.

1 Like

I have tried putting the return below to the assigned, still it shows the same output.
I expect the out put to be “It will take approximately 6 hours” as it should round the value!!

If I call that function it gives name error. that is “NameError: name ‘estimated_time’ is not defined”
:thinking:

You might have to include the changes you made to make it clear to folks what you’ve done. Have a look at the following if you’re adding code to the forums- How do I format code in my posts?

1 Like
def destination_setup(origin, destination, estimated_time, mode_of_transport="Car"):
  print("Your trip starts off in " +origin)
  print("And you are traveling to " +destination)
  print("You will be traveling by "+ mode_of_transport)
  print("It will take approximately " + str(estimated_time) + " hours")
  
def estimated_time_rounded(estimated_time):
  rounded_time = round(estimated_time)
  return rounded_time

trip_planner_welcome("Abdul !")
destination_setup("New Delhi", "Hariyana", 5.65)

The output is as below:

56789101112131415161718

Write your code below:

def trip_planner_welcome(name):
print("Welcome to tripplanner v1.0 " + name)

def destination_setup(origin, destination, estimated_time, mode_of_transport=“Car”):
print("Your trip starts off in " +origin)
print("And you are traveling to " +destination)
print("You will be traveling by "+ mode_of_transport)
print(“It will take approximately " + str(estimated_time) + " hours”)

def estimated_time_rounded(estimated_time):
rounded_time = round(estimated_time)
return rounded_time

trip_planner_welcome(“Abdul !”)
destination_setup(“New Delhi”, “Hariyana”, 5.65)

Output-only Terminal
Output:
Welcome to tripplanner v1.0 Abdul !
Your trip starts off in New Delhi
And you are traveling to Hariyana
You will be traveling by Car
It will take approximately 5.65 hours

Isn’t that the code that works? What section have you used that throws errors?

As noted by @8-bit-gaming, you aren’t calling your estimated_time_rounded function, you’re just telling it to print estimated_time.

2 Likes

https://www.codecademy.com/paths/analyze-data-with-python/tracks/ida-2-introduction-to-python/modules/ida-2-2-python-functions/lessons/intro-to-functions/exercises/functions-review

Can you please locate this exercise?

When I call the function it gives me NameError

NameError: name ‘estimated_time’ is not defined

estimated_time_rounded(estimated_time)

INTRODUCTION TO FUNCTIONS / Review

Following your lesson link, I think they’re asking for simpler. When I did this I ran the rounding function on a time and assigned it to a variable, then used that variable to call the destination_setup function.

it does work if you leave your functions as I quoted earlier and do a function call inside the print statement

print("It will take approximately " + str(estimated_time_rounded(estimated_time)) + " hours")

Thank you, I tried the below and it works, Actually the function called through a variable called estimate

def trip_planner_welcome(name): 
  print("Welcome to tripplanner v1.0 " + name)

def destination_setup(origin, destination, estimated_time, mode_of_transport="Car"):
  print("Your trip starts off in " + origin)
  print("And you are traveling to " + destination)
  print("You will be traveling by " + mode_of_transport)
  print("It will take approximately " + str(estimated_time) + " hours")


def estimated_time_rounded(estimated_time):
  rounded_time = round(estimated_time)
  return rounded_time


trip_planner_welcome(" Abdul ")
estimate = estimated_time_rounded(5.65)
destination_setup(" Delhi ", " Amritsar ", estimate, "Car")

:heartbeat:

1 Like