Case Study: Building Software in Python
Mark Pedigo
Principal Data Scientist
def factorial(n):
if n == 0:
return 1
else:
result = 1
for i in range(1, n + 1):
result *= i
return result
Give feedback concerning:
else
# Original code
def factorial(n):
if n == 0:
return 1
else:
result = 1
for i in range(1, n + 1):
result *= i
return result
# Refactored code def factorial(n): if n < 0: raise ValueError("Not defined")
if n == 0: return 1
result = 1 for i in range(1, n + 1): result *= i return result
Previous formula $$m = P \cdot \frac{r (1 + r)^N}{(1+r)^N - 1}$$ where $m$ is the monthly payment, $P$ is the loan amount, $r$ is the monthly interest rate, and $N$ is the number of monthly payments
New formula $$P = m \cdot \frac{(1+r)^N - 1}{r (1 + r)^N}$$
Case Study: Building Software in Python