Skip to content

Instantly share code, notes, and snippets.

@davegotz
Last active January 22, 2019 16:28
Show Gist options
  • Save davegotz/7ccbee4912c3a7dc83f50c5ed03413be to your computer and use it in GitHub Desktop.
Save davegotz/7ccbee4912c3a7dc83f50c5ed03413be to your computer and use it in GitHub Desktop.
Oil Change Example
# Get the current mileage and the mileage at the last oil change.
current_mileage = int(input("Enter the current mileage: "))
last_change_mileage = int(input("Enter mileage for last oil change: "))
# Check for valid input.
if current_mileage < last_change_mileage:
# Display an error if invalid input is found.
print('The current mileage is less than the last change mileage. Please try again.')
else:
# Calculate difference in mileage
mileage_diff = current_mileage - last_change_mileage
# Check the mileage difference
if mileage_diff > 5000:
print("You need an oil change.")
else:
miles_to_drive = 5000 - mileage_diff
print("You can keep driving for", format(miles_to_drive,",d"), "miles.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment