Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Increase value by 1 for every 500 above 1000

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!

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading