Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can you write algorithm and comment for the fllowing python code. the form of al

ID: 3719050 • Letter: C

Question

Can you write algorithm and comment for the fllowing python code. the form of algorithm and comment show in the picture. Thanks!

Code:

def compute_grade(file_name):

try:

su=0

for s in open(file_name,'r'):

nums=s.split(',')

score= [float(i) for i in nums if i.isdigit() and float(i)>1]

su+=sum(score)/len(score)*float(nums[-1])

return su

except:

return "File not found"

abgorithm: Prints Message based on iteration n 1. Take value n passed to the function 2. Iterate from 0 to n (inclusive) 3. For Each iteration n 4. if i is divisible by both 3 and 5, print FizzBuzz 5. if i is only divisible by 3, print Fizz 6. if i is only divisible by 5, print Buzz 7. else print the number Parameters n Returns: Nothing def fizz buzz(n): for i in range (e, n+1): # iterate from 0 to n inclusive # if i is 0, print 0 elíf í % 3 0 and ¡ % 5-0: # if 1 1s divisible by both 3 and 5 print FizzBuzz elif ? % 3-0: # if i is only divisible by 3, print Fizz elif í % 5- 0: # if I ls only divisible by 5, print Buzz print (0) print ('FizzBuzz')#output message print ('Fizz') print( 'Buzz') print(i) #output message #output message # else print number itself #output message #test case #test case else: fizz_buzz(5) fizz_buzz (15)

Explanation / Answer

# Algorithm : Print the summation of mean of the list element multiplied with last element of the list # 1)Provide a file path to the fuction # 2)Initialise a variable by 0 to maintain sum # 3)For each iteration the file: # 4)Create a list having the file values splitted by ',' as a delimeter # 5)Create a list of digit from the list created above with values greater than 1 # 6)Calculate the sum by multiplying the mean of list by multiplying with the last element of the list def compute_grade(file_name): try: su = 0 # initialize a variable with 0 as initial value for s in open(file_name, 'r'): # iterate over the file with read permission nums = s.split(',') # creating a new split list with ',' as delimeter score = [float(i) for i in nums if i.isdigit() and float(i) > 1] # create a list from above list with digits greater that 1 su += sum(score) / len(score) * float(nums[-1]) # Mean of the the list is multiplied by the last elemnt of the first list created by ',' delimeter return su # Return the sum except: # Catch if any error happens in try block return "File not found" # Return file not found error

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote