2

I have written code to solve a problem.

Here is My Code:

t=int(input())
print("")
while(t):
    s=0
    n=int(input())
    for i in range(n):
        no=int(input())
        s=s+no
    if s%n==0:
        print("YES")
    else:
        print("NO")
    print("")
    t-=1

When I run it on the OS X terminal, it works fine. But when I run it on IDEone or Submit it as a solution, it gives an error on line 5:

ValueError: invalid literal for int() with base 10: ''

I am unsure of what the problem is.

mech
  • 2,775
  • 5
  • 30
  • 38
Abhishek
  • 49
  • 6

1 Answers1

6

You are not handling if the user enters nothing, in other words empty string

>>> int('')
Traceback (most recent call last):
  File "<pyshell#3>", line 1, in <module>
    int('')
ValueError: invalid literal for int() with base 10: ''

You can use a variety of techniques to more robustly accept input from the user.

Cory Kramer
  • 114,268
  • 16
  • 167
  • 218