Question: Python Write down a try block that attempts to assign z = x//y. If a ZeroDivisionError occurs, your code should print Error Code 1 If

Python  Python Write down a try block that attempts to assign z

Write down a try block that attempts to assign z = x//y. If a ZeroDivisionError occurs, your code should print "Error Code 1" If some other error occurs, your code should print "Error Code 2" If no error occurs, your code should print "z was successfully assigned." Lastly, no matter what happens, your code should print "end of program reached '. You should *not* use if statements for this problem, only try. except, else, and finally as needed. b) It is often useful to anticipate what kinds of errors can occur in a piece of code. Name at least four exceptions that could occur from the following lines of code, and identify which line it could occur in. You *can* consider the possibility that new_mod or random.string or m is not defined, hut you should assume that if new mod and random string are defined then they won't cause any errors by themselves. (line 1) >>> import new_mod (line 2) >>> ranstr = newmod.random_string() (line 3) >>> assert type(ranstr) == str (line 4) >>> n = len(ranstr) % m

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!