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")
2 Réponses
+ 4
You can't add a number and a string. You may use multiply for an int and string.
+ 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.