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 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](/WebImages/45/consider-the-following-code-in-each-section-assume-each-sect-1141743-1761612545-0.webp)