'try except block in python

How could I code this in python "try except block? I am to enter a series of numbers to calculate their sum. I want to input the Last digit with "ctrl +d" and then the program should give me the sum of the numbers entered.

sum = 0
while True:
    try:
        n = int(input("Enter a number: ")) 
        sum += n
    except(EOFError, KeyboardInterrupt):
        print(f"Sum of inputs is: {sum}")
        break

That is my code above.

What is wrong with that code?

I am not getting what I want.

I do not want the program to prompt me before I type "ctrl + d" I am to type in my last input(digit) in addition to "crtl+d" and the program would print the sum of all numbers for me.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source