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

1 #write a function called \"angry file finder\" that accepts a 2 #fllename as a

ID: 3708300 • Letter: 1

Question

1 #write a function called "angry file finder" that accepts a 2 #fllename as a parameter. The function should open the file, 3 #read it, and return True if the file contains "1" on every 4 #line. Otherwise the function should return False. 5# 6 #Hint : there are lots of ways to do this. We'd suggest using 7 #either the readline() or readlines() methods. readline() 8 #returns the next line in the file; readlines() returns a 9 #list of all the lines in the file. 10 12 #Write your function here! 13 14 15 16 #Below are some lines of code that will test your function 17 #You can change the value of the variable(s) to test your 18 #function with different inputs. 19 # 20 #If your function works correctly, this will originally 21 #print : True 22 print (angry file finder("AngryFileFinderInput.txt")) 23

Explanation / Answer

def angry_file_finder(filename): f = open(filename, 'r') status = True lines = f.readlines() for line in lines: if line.count('!') == 0: status = False break f.close() return status