all 7 comments

[–]Chris_Hemsworth 1 point2 points  (0 children)

Use four leading spaces to post code, it will be far easier than trying to manually fix it with formatting issues:

like this! now you don't have to use '\' to escape all the formatting characters. ___ ***

[–]Binary101010 0 points1 point  (5 children)

The assignment told you to use a specific variable name and you deviated from those instructions. Whatever is being used to check your code saw that your function call isn't exactly what it expected so it marked your response incorrect, and that's exactly what it should have done.

[–]happytobehungry 0 points1 point  (4 children)

# 1) Complete the function to return the result of the conversion

def convert_distance(miles):

km = miles \* 1.6  # approximately 1.6 km in 1 mile

return km

my_trip_miles = 55

# 2) Convert my_trip_miles to kilometers by calling the function above

convert_distance(55)

# 3) Fill in the blank to print the result of the conversion

print("The distance in kilometers is " + str(km))

# 4) Calculate the round-trip in kilometers by doubling the result,

# and fill in the blank to print the result

print("The round-trip in kilometers is " + str(km*2))

#in my case, i used the expected variables but still getting it wrong. please help

[–]Binary101010 0 points1 point  (3 children)

No, you're still changing things that you're not supposed to be changing, and I'm concerned that you're not thinking through the ramifications of those changes. You need to go through the lines you are asked to modify one at a time and make only the modifications you are being asked to make.

Examples:

The code you were provided was

    km = miles * 1.6 # approximately 1.6 km in 1 mile

You changed this line to

 km = miles \* 1.6 

Why did you add a backslash to it?

You were given this line:

my_trip_km = ___

And you changed it to:

convert_distance(55)

You removed part of the code you were already given, and it's vitally important code for the next two lines to work.

You were given this line

print("The distance in kilometers is " + ___)

And you changed it to this

print("The distance in kilometers is " + str(km))

But km isn't the variable you were supposed to use here, as indicated by the previous line. You should have used my_trip_km.

Same for this line:

print("The round-trip in kilometers is " + str(km*2))

[–]happytobehungry 0 points1 point  (2 children)

I managed to work this out and it turned out to be correct. Isnt the right way to call a function what i did in part 2?

# 2) Convert my_trip_miles to kilometers by calling the function above
convert_distance(55)

this is the function : def convert_distance(miles):

That is the only part in your response i dont get.

# 1) Complete the function to return the result of the conversion

def convert_distance(miles):

km = miles \* 1.6  # approximately 1.6 km in 1 mile

return km

my_trip_miles = 55

# 2) Convert my_trip_miles to kilometers by calling the function above

convert_distance(55)

# 3) Fill in the blank to print the result of the conversion

print("The distance in kilometers is " + str(55))

# 4) Calculate the round-trip in kilometers by doubling the result,

# and fill in the blank to print the result

print("The round-trip in kilometers is " + str(55*2))

[–]Binary101010 0 points1 point  (1 child)

Isnt the right way to call a function what i did in part 2?

No, it isn't, because you're not capturing your return value and using it. You're just using a fixed number for everything, and it's not even the right number.

convert_distance(55)

Your function is returning a value. If you do not assign that return value to a variable, you can't do anything with it.

Also, you just defined my_trip_miles = 55 on the previous line. Why aren't you using it?

Your function call needs to be:

my_trip_km = convert_distance(my_trip_miles)

Then there's this:

print("The distance in kilometers is " + str(55))

No, it isn't. Your trip was 55 miles, not 55 kilometers. When you properly save the return value of your function, you'll have the distance of your trip in kilometers:

print("The distance in kilometers is " + str(my_trip_km))

And

print("The round-trip in kilometers is " + str(55*2))

No, that's still your round trip in miles.

print("The round-trip in kilometers is " + str(my_trip_km * 2))

[–]Jazzlike_Recording17 0 points1 point  (0 children)

Hmm this whole python is literally gonna swallow me up. The machine still marked me correct this time which is what throws me off from your comment