Skip to content

Instantly share code, notes, and snippets.

@Ojha-Shashikant
Last active August 17, 2018 20:13
Show Gist options
  • Save Ojha-Shashikant/e14196f94854f34389b6b69f5e5ef6d4 to your computer and use it in GitHub Desktop.
Save Ojha-Shashikant/e14196f94854f34389b6b69f5e5ef6d4 to your computer and use it in GitHub Desktop.
Using functions calculating number of stops from Bangalore to Goa
''' Using functions calculating number of stops from Bangalore to Goa '''
# odometer reading starting, ending values and calculating the difference
def odometer_reading_difference():
starting_value = float(input("Provide odometer trip starting value in Kms: "))
ending_value = float(input("Provide odometer trip ending value in Kms: "))
if ending_value < starting_value:
print("Starting value cannot be greater than ending value")
exit()
elif ending_value == starting_value:
print("You need to travel to calculate the milege")
exit()
else:
distance_travelled = ending_value - starting_value
return distance_travelled
# taking unit price input of petrol during purchase
def fuel_unit_price():
return float(input("Provide cost of 1 unit of fuel in Rupees: "))
# taking amount paid to purchase the total fuel for the distance
def amount_paid():
return float(input("Provide the total cost paid for single filling in Rupees: "))
# calculating mileage
def mileage():
trip_dist = odometer_reading_difference()
unit_price = fuel_unit_price()
total_amount = amount_paid()
total_fuel_consumed = (total_amount/unit_price)
mileage_of_car = (trip_dist/total_fuel_consumed)
print("Total distance travelled: ", trip_dist, "kms", ", Total fuel consumed: ", total_fuel_consumed, "ltrs")
#filling_based_distance_covered(mileage_of_car, unit_price)
return mileage_of_car
'''
# distance travelled based on one time filling cost
def filling_based_number_of_stops(mlg, unit_p):
new_total_amount = amount_paid()
new_total_fuel_consumed = (new_total_amount/unit_p)
new_number_of_stops = round(560/(mlg*new_total_fuel_consumed))
print("Distance covered in single stop: ", (mlg*new_total_fuel_consumed), "Kms")
return new_number_of_stops
#print("Total distance travelled: ", trip_dist, "kms", ", Total fuel consumed: ", total_fuel_consumed, "ltrs")
'''
# calculating number of stops
def number_of_stops():
mlg = mileage()
print("Mileage of the car is: ", mlg, "Kms/liter")
basic_stops = round(560/mlg)
choice = input("Are you planning to travel at the same cost of filling at every stop? Y/N: ")
if choice == 'Y' or choice == 'y':
print("Distance covered in single stop: ", mlg, "Kms")
return basic_stops
elif choice == 'N' or choice == 'n':
new_total_amount = amount_paid()
unit_price = fuel_unit_price()
fuel_available_for_single_stop = new_total_amount/unit_price
new_number_of_stops = round(560/(mlg*fuel_available_for_single_stop))
print("Distance covered in single stop: ", (mlg*fuel_available_for_single_stop), "Kms")
return new_number_of_stops
else:
print("Distance covered in single stop: ", mlg, "Kms")
print("Input was not as expected therefore your minimum number of stops as per previous info are: ", basic_stops)
return basic_stops
# main function
def main():
stops_count = number_of_stops()
print("Minimum number of stops required to reach from Bangalore to Goa: ", stops_count)
# main starts here
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment