Created
July 18, 2019 05:23
-
-
Save DataSolveProblems/4a0c8ff2bf1fe3dbb89c94b020c09eb1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os, sys | |
import argparse | |
""" | |
Images uploaded with APIPrice per unit | |
First 500 images per monthfree | |
Next 9 500 image compressions $0.009 per image | |
After 10 000 image compressions$0.002 per image | |
""" | |
class PricingCalculator: | |
def __init__(self, image_quantity:int=0): | |
self.qty = image_quantity | |
def calculate_price(self): | |
try: | |
if 501 > self.qty: | |
return 0 | |
elif 10_001 > self.qty: | |
remaining = self.qty - 500 | |
self.total_price = remaining * 0.009 | |
return round(self.total_price, 2) | |
elif self.qty > 10000: | |
remaining = self.qty - 500 | |
remaining = remaining - 9500 | |
self.total_price = remaining * 0.002 + 85.50 | |
return round(self.total_price, 2) | |
except Exception as e: | |
print(e) | |
return None | |
sys.exit() | |
parser = argparse.ArgumentParser(prog='This is my pricing calculator') | |
parser.add_argument('qty', help='Please enter image quantity', type=int) | |
args = parser.parse_args() | |
p = PricingCalculator() | |
p.qty = args.qty | |
total_price = p.calculate_price() | |
print('Total price is ${0:.2f}'.format(total_price)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment