Skip to content
Advertisement

EOFError: EOF when reading a line error in my function

I wrote this function which takes a list of numbers and returns their sum and product:

JavaScript

input:

JavaScript

output:

JavaScript

the problem is that the two print functions are not working. It only prints one of them and for the other I have the EOFError: EOF when reading a line. Do you have any suggestion to change the function in order to don’t have this error?

Advertisement

Answer

You’re calling input() twice, and the second one will try to read another line of input. It’s getting an error because there’s no more input available (I assume you’re using an automated tester — if you run this interactively it will just wait for you to type another line).

Call the function just once, and assign the results to variables. Then you can print the sum and product from this.

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement