Home > Blockchain >  Calculate total amount from Upwork after fee deduction using Python
Calculate total amount from Upwork after fee deduction using Python

Time:04-01

I am trying to calculate total money after deduction of a Fee from Upwork. I found this website that does this but I want to make it using Python. Here is the guidelines from Upwork:

$0-$500 in earnings from a client: 20% service fee applied to earnings.

$500.01-$10,000 in earnings from a client: 10% service fee.

$10,000.01 or more in earnings from a client: 5% service fee.

The code:

budget = int(input("Enter the price (USD): $"))

if 0 <= budget <= 500:
    cut = int((20/100)*budget)
    budget = budget - cut
elif 501.01 <= budget <= 10000:
    cut = int((10/100)*budget)
    budget = budget - cut
elif budget >= 10000.01:
    cut = int((5/100)*budget)
    budget = budget - cut

print(f'Total price after Upwork Fee is ${budget}.')

According to Upwork,

On a $600 project with a new client, your freelancer service fee would be 20% on the first $500 and 10% on the remaining $100. Your earnings after fees would be $490.

I made this calculator but it works only for the first condition $0-$500 in earnings. If the budget is $600, I will get $490 but here I am getting $540. Can someone help me out what went wrong?

--Update--

I also tried this but of no use:

budget = int(input("Enter the price (USD): $"))

a = 0 <= budget <= 500
b = 501.01 <= budget <= 10000
c = budget >= 10000.01

cut1 = int((20/100)*budget)
cut2 = int((10/100)*budget)
cut3 = int((5/100)*budget)    
           

if a:
    cut = cut1
    budget = budget - cut
if a and b:
    cut = cut2
    budget = budget - cut
if a and b and c:
    cut = cut3
    budget = budget - cut

print(f'Total price after Upwork Fee is ${budget}.')

CodePudding user response:

budget = int(input("Enter the price (USD): $"))

def discount(money,percent):
    cut = int((percent/100)*money)
    money= money- cut
    return money

if 0 <= budget <= 500:
    budget = discount(budget ,20)
elif 500.01 <= budget <= 10000:
    budget2 = discount(500 ,20)
    budget = discount(budget-500 ,10)
    budget = budget   budget2
elif budget >= 10000.01:
    budget3 = discount(500 ,20)
    budget2 = discount(10000 ,10)
    budget = discount(budget-10500 ,10)
    budget = budget   budget2   budget3

    

print(f'Total price after Upwork Fee is ${budget}.')

CodePudding user response:

If I understand you correctly, two things are wrong here:

  1. you substract the cut from the budget.
  2. you apply the cut to the max value, not the "diapason" value.

My guess is that you need something like this pesudo-code:

if budget > 0
cut = 0.20*MIN(Budget, 500)
if budget > 500
cut = 0.10*MIN(Budget-500, 9500) // We already applied the cut to the first 500
if budget > 10000
cut = 0.05*(Budget-10000) // we already applied a cut to the first 10000

So:

  1. do not modify budget
  2. accumulate cut
  3. substract it at the end.
  • Related