# Write a function that accepts six project scores. # All scores are out of 100 points, # except the first (which is out of 30), # and the fifth (which is out of 50). # # If any project score is not given, # the function assumes that project's score is zero (0). # (hint: think about "default value") # # The function provides the highest average grade (as integer) # for all the projects by dropping the one with # the lowest percentage. For example, if a student got # a 65% on the first project (out of 30) and # a 55% on the fifth project (out of 50), # that fifth project would be dropped from the average calculation. def template(n1=0, n2=0, n3=0, n4=0, n5=0, n6=0): result = 0 n1 = (n1 * 100) / 30 # percentage n5 = (n5 * 100) / 50 # percentage temp = n1 # running number, so we can decide which one is the lowest if temp > n2: temp = n2 # the current lowest we have been checking if temp > n3: temp = n3 # the current lowest we have been checking if temp > n4: temp = n4 # the current lowest we have been checking if temp > n5: temp = n5 # the current lowest we have been checking if temp > n6: temp = n6 # the current lowest we have been checking # Question: why do we use sequential if statements? # Can we use if-else or if-elif-else? How should we modify the code? total = n1 + n2 + n3 + n4 + n5 + n6 - temp result = total / 5 # average, compute from (total - dropped prpoject) / 5 projects remaining return int(result) # END OF YOUR CODE test1 = template(n2=100, n3=100, n4=100, n5=50, n6=100) # why don't we pass in n1=0 ? test2 = template(n1=30, n3=100, n4=100, n5=50, n6=100) test3 = template(n1=30, n2=100, n4=100, n5=50, n6=100) test4 = template(n1=30, n2=100, n3=100, n5=50, n6=100) test5 = template(n6=100, n1=30, n2=100, n4=100, n3=100) test6 = template(n2=100, n3=100, n4=100, n5=50, n1=30) test7 = template(n2=55, n3=55, n4=55, n6=55, n1=15, n5=25) test8 = template(n5=25, n4=100, n6=100) # pass in 4 arguments (without name, i.e., positioning) # use defaults for the remaining parameters (i.e., n5 and n6) test9 = template(25, 90, 90, 100) # Notice that, from the above function call, # we cannot use defaults of n1 and n2. # This is because calling function without using named arguments # requires arguments to be passed in order. # Therefore, if a function definition has 6 parameters, # (from this function call) the first 4 parameters # will get the values being passed in # and the defaults will be used for the remaining parameters. # Good practice: when there are default values, make use of them # --> use the maximum number of defaults if test1 == 100: print("test1", test1, "You got it RIGHT!") else: print("test1", test1, "Please check your code") if test2 == 100: print("test2", test2, "You got it RIGHT!") else: print("test2", test2, "Please check your code") if test3 == 100: print("test3", test3, "You got it RIGHT!") else: print("test3", test3, "Please check your code") if test4 == 100: print("test4", test4, "You got it RIGHT!") else: print("test4", test4, "Please check your code") if test5 == 100: print("test5", test5, "You got it RIGHT!") else: print("test5", test5, "Please check your code") if test6 == 100: print("test6", test6, "You got it RIGHT!") else: print("test6", test6, "Please check your code") if test7 == 54: print("test7", test7, "You got it RIGHT!") else: print("test7", test7, "Please check your code") if test8 == 50: print("test8", test8, "You got it RIGHT!") else: print("test8", test8, "Please check your code") if test9 == 72: print("test9", test9, "You got it RIGHT!") else: print("test9", test9, "Please check your code")