0

the first line is wrong in try block but the second is not wrong then why it shows 'error occurred '

try: variable = 10 print(variable + "hello") print(variable / 2) except ZeroDivisionError: print("Divided by zero") except (ValueError, TypeError): print("Error occurred")

6th Jun 2022, 11:40 AM
Purple Phoenix 7
Purple Phoenix 7 - avatar
2 odpowiedzi
+ 4
You can't add a number and a string. You may use multiply for an int and string.
6th Jun 2022, 12:19 PM
Paul
Paul - avatar
+ 2
I saw your other question, this is allowed: try: variable = 10 print(variable + "hello") print(variable / 2) except: print("Error occurred") But you won't know which error occurred.
6th Jun 2022, 12:28 PM
Paul
Paul - avatar