Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions BugsDocumentation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Documentaion of Bugs found
1. snippets/__init__.py
- import code in snippets.__init__ had been commented out and so the import were not happening
2. loop.py
- line 9: initialize dict instead of list
3. loop.py
- line 11: forgot to add range(10)
- line 13: NameError cause of using undefined variable
- line 13: use list.push instead of list.append
4. io.py
- line 16: list comprehension should use the [] symbols instead of {}
- line 18: syntax error, there is no such operator as !===, instead use '==' operator
- line 20: use python inbuilt sum
- line 29: use python inbuilt sum
- line 38: use python inbuilt sum
- line 39: use python inbuilt len
- line 15, 24, 34
- use [] to access the values of the dict
- line 18: should avoid using is operator for immutable types such as strings and numbers, the result is unpredictable, instead use ==
- line 45: test for division by zero, by checking if sum is zero

5. foobar.py
- line 8: remove default list argument and initialize it inside the function (explanation below)

Please note: Any expressions in default arguments are always calculated when the function is defined and not when it is called. So when function is called the first time the 'bar' list is created, any subsequntial calls will still use the same list. To avoid this just define bar inside the function and not as a default argument.

14 changes: 7 additions & 7 deletions snippets/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# from .loop import lambda_array
# from .io import (
# read_file,
# calculate_unpaid_loans,
# calculate_paid_loans,
# average_paid_loans
# )
from .loop import lambda_array
from .io import (
read_file,
calculate_unpaid_loans,
calculate_paid_loans,
average_paid_loans
)
from .foobar import foo
3 changes: 2 additions & 1 deletion snippets/foobar.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""


def foo(bar=[]):
def foo():
bar = []
bar.append("baz")
return bar
42 changes: 25 additions & 17 deletions snippets/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,38 @@ def read_file():


def calculate_unpaid_loans(data):
loans = data("loans")
unpaid_loans = {
loan.amount for loan in loans
if loan.status !== "unpaid"
}
return sun(unpaid_loans)
try:
loans = data["loans"]
unpaid_loans = [
loan["amount"] for loan in loans
if loan["status"] == "unpaid"
]
except KeyError as error:
print(error, 'could not access some keys from the json format')
return sum(unpaid_loans)


def calculate_paid_loans(data):
loans = data("loans")
paid_loans = [
loan.amount for loan in loans
if loan.status is "paid"
]
return sun(paid_loans)
try:
loans = data["loans"]
paid_loans = [
loan["amount"] for loan in loans
if loan["status"] == "paid"
]
except KeyError as error:
print(error, 'could not access some keys from the json format')
return sum(paid_loans)


def average_paid_loans(data):
loans = data("loans")
loans = data["loans"]
paid_loans = [
loan.amount for loan in loans
if loan.status is "paid"
loan["amount"] for loan in loans
if loan["status"] == "paid"
]
sum_paid_loans = sun(paid_loans)
number_paid_loans = length(paid_loans)
sum_paid_loans = sum(paid_loans)
number_paid_loans = len(paid_loans)
if(sum_paid_loans == 0):
return 0
average = (sum_paid_loans/number_paid_loans)
return average
6 changes: 3 additions & 3 deletions snippets/loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

def lambda_array():
# initialize an empty array
lambda_methods = {}
lambda_methods = []
# implement a for loop to count from 0 to 9
for i in 10:
for i in range(10):
# append the lambda function to the array defined above
lambdamethods.push(lambda x: x + i)
lambda_methods.append(lambda x: x + i)

return lambda_methods