Skip to content

Instantly share code, notes, and snippets.

@maciejjankowski
Last active January 9, 2019 12:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maciejjankowski/536d2031faeeaab765b98008b48a45eb to your computer and use it in GitHub Desktop.
Save maciejjankowski/536d2031faeeaab765b98008b48a45eb to your computer and use it in GitHub Desktop.
Refactoring exercises
# https://github.com/RefactoringGuru/refactoring-examples/tree/master/simple/python
# 1
def disabilityAmount():
if seniority < 2:
return 0
if monthsDisabled > 12:
return 0
if isPartTime:
return 0
# 2
if isSpecialDeal():
total = price * 0.95
send()
else:
total = price * 0.98
send()
# 3
if date.before(SUMMER_START) or date.after(SUMMER_END):
charge = quantity * winterRate + winterServiceCharge
else:
charge = quantity * summerRate
# 4
def printOwing(self):
self.printBanner()
# print details
print("name:", self.name)
print("amount:", self.getOutstanding())
# 5
def discount(inputVal, quantity):
if inputVal > 50:
inputVal -= 2
return inputVal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment