What is the output of the following code if the user enters a 0?
try: value = input("Enter a value: ") print(int(value)/len(value)) except ValueError: print("Bad input...") except ZeroDivisionError: print("Very bad input...") except TypeError: print("Very very bad input...") except: print("Booo!")
- 0.0
- Very bad input…
- 1.0
- Very very bad input…
- Bad input…
- Booo!
Explanation: The program will print 0.0 because the following expression int(0) / len(“0”) evaluates to 0.0 (0 / 1 → 0.0), so the program flow does not enter any of the except branches, and no exception is raised.
More Questions: Python Essentials 1 (PE1) Course Final Test
Please login or Register to submit your answer