I have finalized the code for this assignment however when I print the results it is only printing one True/False value for each function. For dict1 and dict2 it is supposed to reiterate and return multiple values.
Current outcome is:
False
True
False
The expected outcome is:
print(fullCoverageClearance(dict1)) -> [False, True]
print(fullCoverageClearance(dict2)) -> [False, True, False, True]
print(fullCoverageClearance(dict3)) -> [False]
Code is as follows:
dict1 = {"JS" : {"Paid" : [200, 400, 500, 600]}, "SK" : {"Paid": [400, 1000, 1600]}}
dict2 = {"JS" : {"Paid" : [200, 400, 500, 600]}, "SK" : {"Paid": [1010, 2000]}, "MJ":{"Paid" : [5, 6, 7]}, "ZF" : {"Paid": [2660, 500]}}
dict3 = {"SK" : {"Paid" : [200, 400]}}
def fullCoverageClearance(dict1):
total1 = [sum(dict1["JS"]["Paid"]), sum(dict3["SK"]["Paid"])]
for i in total1:
if i <= 3000:
return 'False'
else:
return 'True'
def fullCoverageClearance(dict2):
total2 = [sum(dict2["JS"]["Paid"]), sum(dict2["SK"]["Paid"]), sum(dict2["MJ"]["Paid"]), sum(dict2["ZF"]["Paid"])]
for i in total2:
if i <= 3000:
return 'False'
else:
return 'True'
def fullCoverageClearance(dict3):
total3 = [sum(dict3["SK"]["Paid"])]
for i in total3:
if i <= 3000:
return 'False'
else:
return 'True'
print(fullCoverageClearance(dict1))
print(fullCoverageClearance(dict2))
print(fullCoverageClearance(dict3))
CodePudding user response:
Reading your code, its confusing what you're trying to accomplish. Maybe this will put you down the right path:
dict1 = {"JS" : {"Paid" : [200, 400, 500, 600]}, "SK" : {"Paid": [400, 1000, 1600]}}
def fullCoverageClearance(vals):
totals = [sum(vals["JS"]["Paid"]), sum(vals["SK"]["Paid"])]
print(totals)
results = []
for amt in totals:
print(amt)
if amt <= 3000:
results.append(False)
else:
results.append(True)
return results
print(fullCoverageClearance(dict1))
# Output
# [1700, 3000]
# 1700
# 3000
# [False, False]
CodePudding user response:
If I read the question correctly this is what you want, I didn't change the conditions which means the actual output is this:
[False, False]
[False, True, False, True]
[False]
The reason that the first output is false and false, is that the second value is exactly 3000 which evaluates the condition to true out putting a false
dict1 = {"JS" : {"Paid" : [200, 400, 500, 600]}, "SK" : {"Paid": [400, 1000, 1600]}}
dict2 = {"JS" : {"Paid" : [200, 400, 500, 600]}, "SK" : {"Paid": [1010, 2000]}, "MJ":{"Paid" : [5, 6, 7]}, "ZF" : {"Paid": [2660, 500]}}
dict3 = {"SK" : {"Paid" : [200, 400]}}
def fullCoverageClearance1(dict1):
total1 = [sum(dict1["JS"]["Paid"]), sum(dict1["SK"]["Paid"])]
results = []
for i in total1:
if i <= 3000:
results.append(False)
else:
results.append(True)
return results
def fullCoverageClearance2(dict2):
total2 = [sum(dict2["JS"]["Paid"]), sum(dict2["SK"]["Paid"]), sum(dict2["MJ"]["Paid"]), sum(dict2["ZF"]["Paid"])]
results = []
for i in total2:
if i <= 3000:
results.append(False)
else:
results.append(True)
return results
def fullCoverageClearance3(dict3):
total3 = [sum(dict3["SK"]["Paid"])]
results = []
for i in total3:
if i <= 3000:
results.append(False)
else:
results.append(True)
return results
print(fullCoverageClearance1(dict1))
print(fullCoverageClearance2(dict2))
print(fullCoverageClearance3(dict3))
If you use return the whole function will just quit out and work on the next function which only outputs one value.
Also, you function names are over lapping which overrides the previous stated functions.
def fullCoverageClearance(dict1):
total1 = [sum(dict1["JS"]["Paid"]), sum(dict3["SK"]["Paid"])]
for i in total1:
if i <= 3000:
return 'False'
else:
return 'True'
if you look at the variable total1 second element, you see that there is a typo. Be sure that you double check you code.