Abir Hasan I don't think that's what he meant. But exception handling like you did is probably the best approach.
Saeed Hayati you can do something like this
sum = 0
sum += int(input())
This code ignores input lines that can't be cast to integer (ValueError)