Question: def doSomething(data, i, new): data[i] = new # data modification attack return data 8 [5pts, short answering]. As commented in the above code, this function
def doSomething(data, i, new):
data[i] = new # data modification attack
return data
8 [5pts, short answering]. As commented in the above code, this function modifies the data inside and returns the data, which may be different from what was passed from the caller. To avoid it, the caller uses a special data type. What data type should be used?
9-10 [5pts each, filling in blanks]. In this case, an exception should be handled as follows. Fill in the blanks.
def doSomething(data, i, new):
______: # Question for Q9
data[i] = new
return data
______ MyTypeError as e: # Question for Q10
print(e)
11-12 [5pts each, filling in blanks]. In the function for exception handling, note the exception MyTypeError is NOT built-in but it is supposed to be defined. Assume yet another class an exception handler, called MyError, which is a subclass to BaseException. Fill in the blanks below to complete MyTypeError exception class.
(1) class MyTypeError( _________ ): # question for Q10
(2) def __init__(self, m):
(3) self.message = ____________ # question for Q11
(4) def __str__(self): # a method __str__() that can display the message, which is assigned when an object is instantiated.
# this method is activated when this object is to be printed.
(5) return self.message
(6) pass
- - - - - - - - - - My Answer - - - - - - - - - -
8)
9)
10)
11)
12)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
