Wednesday, April 28, 2021

IslandT: Create a function with python to count the fuel

You were camping with your friends far away from home, but when it’s time to go back, you realize that your fuel is running out and the nearest pump is 50 miles away! You know that on average, your car runs on about 25 miles per gallon. There are 2 gallons left. Considering these factors, write a function that tells you if it is possible to get to the pump or not. The function should return true (1 in Prolog) if it is possible and false (0 in Prolog) if not. The input values are always positive.

def zero_fuel(distance_to_pump, mpg, fuel_left):
    
    if distance_to_pump <= mpg * fuel_left:
        return True
    else:
        return False

The above solution is simple, but maybe you have a better idea, do share your idea below!



from Planet Python
via read more

No comments:

Post a Comment

TestDriven.io: Working with Static and Media Files in Django

This article looks at how to work with static and media files in a Django project, locally and in production. from Planet Python via read...