Skip to content

Instantly share code, notes, and snippets.

@darighost
Created December 17, 2022 16:36
Show Gist options
  • Save darighost/b900b614408fe0fcf76e944206287514 to your computer and use it in GitHub Desktop.
Save darighost/b900b614408fe0fcf76e944206287514 to your computer and use it in GitHub Desktop.
Script to figure out how much a contract on Upwork must pay to come out to a certain real total for the freelancer
from itertools import chain, repeat
def is_floatable(num):
try:
float(num)
return True
except ValueError:
return False
# based on this glorious StackOverflow post: https://stackoverflow.com/a/56081775
def number_input(
prompt="Enter a number: ",
error="Not a number! Try again: "):
prompts = chain([prompt], repeat(error))
replies = map(lambda i: int(input(i)), prompts)
valid_response = next(filter(is_floatable, replies))
return valid_response
# money you want to actually receive on the current contract
desired_income_USD = number_input(
'How much money to you want to make after fees: ')
# money the client has already paid you on previous contracts
# (how much the client PAID, not how much you RECEIVED after service fees!)
amount_already_paid_from_same_client_USD = number_input(
'How much money has the client paid you (not counting fees): ')
T = desired_income_USD
A = amount_already_paid_from_same_client_USD
# for a desired final income of $T, with a client who has already paid you $A
max_80_pct = min(500, (max(T - A, 0) / .8))
print(max_80_pct)
real_T = max_80_pct + (T - (max_80_pct * .8)) / .9
print(f'You must charge $%.2f to make a total of ${T} for a client who has already paid you ${A} (of which $%.2f will go to fees)' % (real_T, real_T - T))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment