# Calculate total amount from upwork after fee deduction using python

When working as a freelancer on platforms like Upwork, it is important to calculate the total amount you will receive after deducting the platform’s fees. In this article, we will explore three different ways to solve this problem using Python.

## Option 1: Using Basic Arithmetic Operations

The first option is to use basic arithmetic operations to calculate the total amount after fee deduction. We can start by taking the input of the total amount earned and the fee percentage. Then, we can calculate the fee amount by multiplying the total amount by the fee percentage divided by 100. Finally, we can subtract the fee amount from the total amount to get the final amount received.

``````
total_amount = float(input("Enter the total amount earned: "))
fee_percentage = float(input("Enter the fee percentage: "))

fee_amount = total_amount * (fee_percentage / 100)
final_amount = total_amount - fee_amount

print("Total amount after fee deduction: ", final_amount)
``````

## Option 2: Using a Function

The second option is to encapsulate the calculation logic in a function. This can make the code more modular and reusable. We can define a function called `calculate_final_amount` that takes the total amount and fee percentage as parameters. Inside the function, we can perform the same calculations as in option 1 and return the final amount.

``````
def calculate_final_amount(total_amount, fee_percentage):
fee_amount = total_amount * (fee_percentage / 100)
final_amount = total_amount - fee_amount
return final_amount

total_amount = float(input("Enter the total amount earned: "))
fee_percentage = float(input("Enter the fee percentage: "))

final_amount = calculate_final_amount(total_amount, fee_percentage)
print("Total amount after fee deduction: ", final_amount)
``````

## Option 3: Using a Class

The third option is to create a class that represents the calculation of the final amount. We can define a class called `UpworkCalculator` with a method called `calculate_final_amount`. This method will take the total amount and fee percentage as parameters and perform the necessary calculations to return the final amount.

``````
class UpworkCalculator:
def calculate_final_amount(self, total_amount, fee_percentage):
fee_amount = total_amount * (fee_percentage / 100)
final_amount = total_amount - fee_amount
return final_amount

total_amount = float(input("Enter the total amount earned: "))
fee_percentage = float(input("Enter the fee percentage: "))

calculator = UpworkCalculator()
final_amount = calculator.calculate_final_amount(total_amount, fee_percentage)
print("Total amount after fee deduction: ", final_amount)
``````

After considering these three options, the best approach depends on the specific requirements of your project. If you only need to perform this calculation once, option 1 using basic arithmetic operations is the simplest and most straightforward. However, if you anticipate needing to perform this calculation multiple times or in different parts of your code, options 2 and 3 using a function or a class respectively provide better modularity and reusability.

Rate this post

### 8 Responses

1. Darian says:

Option 2 using a function is the way to go, Python power! 💪🐍

2. Jalen says:

Option 2 is like a superhero swooping in to save the day! Functions FTW! 💪🦸‍♂️

3. Kimber Tapia says:

Option 3 seems like overkill. Why complicate things when basic arithmetic gets the job done? 🤷‍♀️

4. Leah Hansen says:

Option 3 is like having a fancy car for a simple grocery run. Too much unnecessary complexity!

5. Douglas says:

Option 3 using a class seems like overkill for a simple calculation. Stick with option 1!

1. Emery says:

I respectfully disagree. While option 1 may work for a simple calculation, opting for a class in option 3 allows for scalability and code reusability. Its always better to plan for future growth rather than limit ourselves to immediate needs.

6. Nathalia Anthony says:

Option 3 seems like a fancy way to do basic math. Stick with Option 1, folks! 🧮😎

7. Barrett says:

Option 3: Using a Class seems like an overcomplication. Why not keep it simple with Option 1? 🤔