ty76 August 3, 2020 By Paul Browning 1. The following code has an error, which code should you use to fix it? def multiply_together(a,b,c): return a * B * c x = multiply_together(7,7,7) print(x) return a * b * creturn(A * B * C)return a * barea = a * B * c return areaQuestion 1 of 10 2. The following code has an error, which line is it on? 1: f=open(input("Enter a filename: ")) 2: 3: while True: 4: line=f.readline() 5: 6: if line == "" 7: break 8: else: 9: print(line) 1769Question 2 of 10 3. The following code has an error, which line is it on? 1: ourlist = ['S','O','T','Z','P','M'] 2: 3: def letterac(name,bound=2,letters): 4: #Add the letters together 5: result = 0 6: timesdone = 0 7: for letter in letters: 8: if letter in name: 9: while timesdone <= bound: 10: result += 1 11: timesdone += 1 12: return result 13: 14: 15: print(letterac("JAMES",2,ourlist)) 31915Question 3 of 10 4. Which exception will the following code raise? z = 5+8+”9” IndentationErrorValueErrorArithmeticErrorTypeErrorQuestion 4 of 10 5. You need to handle an exception for opening a file, how do you do it? try: f = open("numbers.txt") except FileNotFoundError: print("This doesn't exist") else: print(f.read()) finally: f.close() try: f = open("numbers.txt") except FileNotFoundError: print("This doesn't exist") else: print(f.read()) f.close() try: f = open("numbers.txt") except FileNotFoundError: print("This doesn't exist") finally: print(f.read()) f.close() try: f = open("numbers.txt") except: print("This doesn't exist") else: print(f.read()) f.close() Question 5 of 10 6. Look at the following code - what line is the error on? 1: items = [] 2: 3: def getdata(): 4: item = input("Enter a grade: ") 5: items.append(item) 6: 7: def getaverage(items): 8: sum = 0 9: for i in items: 10: sum += i 11: return round(sum/len(items)) 12: 13: i = 3 14: for v in range(1,5): 15: getdata() 16: print(getaverage(items)) 3141610Question 6 of 10 7. You need to catch two errors, TypeError and ZeroDivisionError. How would you code this? except DivideByZero|TypeError as e:except as e:except(TypeError,ZeroDivisionError) as e:except(TypeError,ZeroDivisionError) from e:Question 7 of 10 8. You’re creating a new class to catch exceptions, which code do you use? class MyException(Exception):class MyException(SystemError):class MyException():class MyException(Except):Question 8 of 10 9. The following code has an error, which exception will be raised? f = open(‘number.txt’) f.readall() SystemErrorValueErrorAttributeErrorIndentationErrorQuestion 9 of 10 10. The following code has an error, which exception will be raised? i = 3 for v in i: pass TypeErrorSyntaxErrorIndentationErrorValueErrorQuestion 10 of 10 Loading...