try:
f1=int(input("enter first digit"))
f2=int(input("enter second digit"))
answ=(f1/f2)
print (answ)
except ZeroDivisionError:
-5
A
回答
1
0
在Python中,當您編寫':'時,您將啓動一個代碼塊。而且,按照語法,您不能將塊保留爲空。
所以,你必須完成block.e.g。
try :
f1=int(input("enter first digit"))
f2=int(input("enter second digit"))
answ=(f1/f2)
print (answ)
except ZeroDivisionError::
print ("You can't divide by zero")
+1
非常感謝你 – hunk
+0
第6行的語法錯誤。** :: **應該替換爲**:** –
我沒有看到在這裏downvotes的理由。我認爲這個特定的語法錯誤是神祕的,因爲它可能是由許多原因造成的。只需查看[documentation](https://docs.python.org/2/tutorial/errors.html#handling-exceptions)來處理異常,這可能是不夠的。雖然在那裏提到了「SomeError:pass除外」的語法,但沒有明確指出塊不能留空,這對於初學者來說可能會令人費解。 – Reti43