title: try except block in python
body: <p>How could I code this in python &quot;try except block?
  I am to enter a series of numbers to calculate their sum. I want to input the Last digit with &quot;ctrl +d&quot; and then the program should give me the sum of the numbers entered.</p>
  <pre><code>sum = 0
  while True:
      try:
          n = int(input(&quot;Enter a number: &quot;)) 
          sum += n
      except(EOFError, KeyboardInterrupt):
          print(f&quot;Sum of inputs is: {sum}&quot;)
          break
  </code></pre>
  <p>That is my code above.</p>
  <p>What is wrong with that code?</p>
  <p>I am not getting what I want.</p>
  <p>I do not want the program to prompt me before I type &quot;ctrl + d&quot;
  I am to type in my last input(digit) in addition to &quot;crtl+d&quot; and the program would print the sum of all numbers for me.</p>