Home > Software design >  Increase value by 1 for every 500 above 1000
Increase value by 1 for every 500 above 1000

Time:01-23

I want to make a distance calculator, my wish is to create it so that price of shipping will increase by 1$ for ever 500 above 1000 for example: Example 1: If the delivery distance is 1499 meters, the delivery fee is: 2€ base fee 1€ for the additional 500 m => 3€ Example 2: If the delivery distance is 1500 meters, the delivery fee is: 2€ base fee 1€ for the additional 500 m => 3€ Example 3: If the delivery distance is 1501 meters, the delivery fee is: 2€ base fee 1€ for the first 500 m 1€ for the second 500 m => 4€ I can't figure this out on my own...I suck at math apparently, appreciate the help!

CodePudding user response:

You can subtract 1000 from the initial value and then use integer divison to check how many times it has gone 500 above
example below in python:

a = input()
b = a-1000
if b<=0:
    print("2 dollars")
else:
    print(3 b//500) #3 because its over 1000 so at least first 500 are included
  •  Tags:  
  • Related