Consider the following code in each section Assume each sect

Consider the following code in each section. Assume each section is dependent. What is printed on the screen? 1st = [1, 2, 3] try: a = 1st [2 &3] except Value Error: print (\'Bad\') sys.exit (1) print (a) sys.exit (0) try: a = int (\'x15\') print (a) sys.exit(0) except ValueError: print (\'Bad\') sys.exit (1) x = 5 y = 0 try: print (y/y) except: print (y/x) sys.exit(1) sys.exit(0)

Solution

a.

lst = [1, 2, 3]
try:
a = lst[2%3]
except ValueError:
print \'Bad\'
sys.exit(1)
print a
sys.exit(0)

This will print the value 3 to the screen.

b.

try:
a = int(\'X15\')
print a
sys.exit(0)
except ValueError:
print \'Bad\'
sys.exit(1)

This will print the value Bad to the screen.

x = 5
y = 0
try:
print x / y
except:
print y / x
sys.exit(1)
sys.exit(0)

This will print the value 0 to the screen.

 Consider the following code in each section. Assume each section is dependent. What is printed on the screen? 1st = [1, 2, 3] try: a = 1st [2 &3] except Va

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site