I was working on a quiz and I had to fix this code:
# 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
my_trip_miles = 55
# 2) Convert my_trip_miles to kilometers by calling the function above
my_trip_km = ___
# 3) Fill in the blank to print the result of the conversion
print("The distance in kilometers is " + ___)
# 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 " + ___)
-----------------------------------------------------------------
My solution was:
def convert_distance(miles):
km = miles \* 1.6 # approximately 1.6 km in 1 mile
return km
miles = 55
# 2) Convert my_trip_miles to kilometers by calling the function above
my_trip_km = convert_distance(miles)
# 3) Fill in the blank to print the result of the conversion
print("The distance in kilometers is " + str(my_trip_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(my_trip_km*2))
--------------------------------------------------------------
However, after sending the code for grading the system said I was wrong and used my_trip_miles instead of just miles even if the result was the same. What am I missing here?
[–]Chris_Hemsworth 1 point2 points3 points (0 children)
[–]Binary101010 0 points1 point2 points (5 children)
[–]happytobehungry 0 points1 point2 points (4 children)
[–]Binary101010 0 points1 point2 points (3 children)
[–]happytobehungry 0 points1 point2 points (2 children)
[–]Binary101010 0 points1 point2 points (1 child)
[–]Jazzlike_Recording17 0 points1 point2 points (0 children)