Python Forum
unexpected EOF while parsing - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: unexpected EOF while parsing (/thread-16670.html)



unexpected EOF while parsing - whatloop - Mar-09-2019

On executing the script the python prompts for number until the user enters null as an input
def main():
        total = 0 
        number = input('Enter a number : ')
        while number != '':
                total += int(number)
                number = input('Enter a number : ')
        print('Sum of all input number is : ',total)
if __name__=='__main__':
        main()

Error
python sumNumbers.py 
Enter a number : 2
Enter a number : 2
Enter a number : 2
Enter a number : 
Traceback (most recent call last):
  File "sumNumbers.py", line 9, in <module>
    main()
  File "sumNumbers.py", line 6, in main
    number = input('Enter a number : ')
  File "<string>", line 0
    
    ^
SyntaxError: unexpected EOF while parsing



RE: unexpected EOF while parsing - snippsat - Mar-09-2019

You never break out of the loop.
In a function can use return as return always get value out and exit function.
indentation is 4-space not 8.
def main():
    total = 0
    number = input('Enter a number : ')
    while number != '':
        total += int(number)
        number = input('Enter a number : ')
    return f'Sum of all input number is : {total}'

if __name__=='__main__':
    print(main()) 



RE: unexpected EOF while parsing - samsonite - Mar-09-2019

Besides ... get a glance to Python powerful!
Output:
C:\Training>python somma.py Enter a number : 1234567890123456789012345678901234567890123456789012345678901234567890 Enter a number : 1 Enter a number : Sum of all input numbers is : 1234567890123456789012345678901234567890123456789012345678901234567891
Cheers


RE: unexpected EOF while parsing - whatloop - Mar-09-2019

thanks a lot snippsat