# FAQ: Introduction to Functions - Review

Try changing

``````rounded_time = round(estimated_time, 0)
``````

to

``````rounded_time = round(estimated_time)
``````

Perhaps it may be causing a mismatch with the expected output. e.g.

``````x = 32.45
y = round(x)
z = round(x, 0)

print(y)
# 32
print(type(y))
# <class 'int'>

print(z)
# 32.0
print(type(z))
# <class 'float'>
``````
3 Likes

Interesting type coercion in play, or what could be perceived as such. Somewhere in the pipe between the function and the variable Python cast the value as `int`, and would have assigned it memory if it didn’t already exist in memory. The outcome will be the `id` of the stored value, in either case, on the proviso that Python does not allow duplicate values in memory. The existing value is the one that will be given back to the assignment as an `id` reference.

That worked, thanks so much!

1 Like

I can’t seem to clear step one, yet I get the proper result. Finally figured this out and wanted to share in case others have the same issue. My format was correct but I discovered that I’d used a uppercase V1.0 instead of the lowercase v1.0

The first paragraph states we’re building TripPlanner V1.0, while the desired output shows "Welcome to tripplanner v1.0

Hope this helps somebody. I struggled with this for over an hour before I realized the mistake.

Hi there! Would somebody be so kind to help me understand why i can’t go further?

1 Like
``````rounded_time = round(estimated_time, 1)
``````

returns a float.

Consider changing to:

``````rounded_time = round(estimated_time)
``````

so that it returns an integer.

1 Like

It worked man!!! Thanks a lot!!!

1 Like

A ‘rounded integer’ to boot, which means closest integer. Mind, Python behaves a bit arbitrarily in terms of number parity, treating odd numbers different to evens. If you know more about this, we’re all ears.

1 Like

Tough to explain, or figure out, but here is a log out…

``````>>> for x in range(20):
...       print (round( x / 2))
...
...
0
0
1
2
2
2
3
4
4
4
5
6
6
6
7
8
8
8
9
10
>>>
``````

The sequence,

``````8  15 / 2  =>  round up (expected)
8  16 / 2  =>  expected
8  17 / 2  =>  round down (unexpected)
``````

This is the logic I don’t quite understand.

Actually, in rounding to integers, there is a consistent pattern.

As the documentation mentions,
https://docs.python.org/3/library/functions.html#round

… if two multiples are equally close, rounding is done toward the even choice (so, for example, both `round(0.5)` and `round(-0.5)` are `0`, and `round(1.5)` is `2`).

The motivation behind this being: (Bankers' Rounding | Microsoft Learn)

However, when trying to to round floats in Python, then the above doesn’t hold (because of the limitations of floating point arithmetic). See the comment (in documentation of the round function):

`2.675` is just an example. The issue is true for floating points in general. The link in the documentation about floating point limitations goes in more detail about the representation error etc. With integers, at least the pattern is consistent. That isn’t true for floats. There is a `decimal` module to address this.

Another related thread: Python 3.x rounding behavior - Stack Overflow

1 Like

Unsure what I’ve done wrong here.

See earlier post: FAQ: Introduction to Functions - Review - #125 by mtrtmk

def trip_planner_welcome(name):
print("Welcome to tripplanner v1.0 ", name)
#trip_planner_welcome(“JCarlos”)

def estimated_time_rounded(estimated_time):
rounded_time = round(estimated_time, 0)
return rounded_time
estimate = estimated_time_rounded(2.5)

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” )

destination_setup(“Houston”, “Australia”,estimate, “Airplane”)

This is my code, I followed all the instructions and idk what is wrong with my code, it shows me the output well but its stills telling me the same thing that you got in your review

You are not printing the exact statements specified in the instructions.
For Example, your spacing in multiple print statements isn’t correct:

``````# You wrote:
print("Your trip starts off in ", origin)
# "Your trip starts off in  Houston"

# Expected output:
# "Your trip starts off in Houston"

# You can fix it by doing:
print("Your trip starts off in", origin)
# OR
print("Your trip starts off in " + origin)
``````

Also, you wrote:

``````rounded_time = round(estimated_time, 0)
``````

See this post: FAQ: Introduction to Functions - Review - #125 by mtrtmk

step 13/13

my code:

name = “Mate”
def trip_planner_welcome(name):
print("Welcome to tripplanner v1.0 " + name)

trip_planner_welcome(name)

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

estimate = estimated_time_rounded(4.5)

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

print("Your trip starts off in "+ origin)
print("And you are travelling to "+ destination)
print("You will be travelling by "+ mode_of_transport)
print("It will take approximetely "+ str(estimate) + " hours ")

the output looks great, but i still got Did you use `print()` with the string `"It will take approximately ____ hours "` concatenated with the parameter `estimated_time` in the blank?

It’s driving me crazy for an hour already, help!

Solved, but i dont know how, i just copied word approximately thinking maybe i spelled it wrong, didnt see any changes, clicked run again and it marked green, very frustrating

Your output must match the string specified in the instructions exactly.

The instructions specify `'traveling'` whereas you have used the British English spelling `'travelling'`
You have misspelled `'approximately'` as `'approximetely'`
You also have a stray space at the end of one of the strings i.e.     `+ " hours "`    instead of     `+ " hours"`

1 Like

Thank you very much for your help

1 Like

Why doesn’t 2.5 round up to 3, but 1.5 does to 2?

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

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

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(estimate)+” hours”)
destination_setup(“Party House”,“Home Bed”,estimate)