Skip to main content
deleted 404 characters in body
Source Link
user2555451
user2555451

There are two things wrong here. First, You need parenthesis to enclose the errors:

except (ValueError,IOError) as err:

See a demonstration below:

>>> try:
...     1/0
... except Exception,Exception as e:
  File "<stdin>", line 3
    except Exception,Exception as e:
                                ^
SyntaxError: invalid syntax
>>> try:
...     1/0
... except (Exception, Exception) as e:
...     print e
...
integer division or modulo by zero
>>>

Second, you need a try to go with that except line:

def average():
    try:
        TOTAL_VALUE = 0
        FILE = open("Numbers.txt", 'r')

        for line in FILE:
            AMOUNT = float(line)
            TOTAL_VALUE += AMOUNT
            NUMBERS_AVERAGE = TOTAL_VALUE / AMOUNT
        print("the average of the numbers in 'Numbers.txt' is :",
            format(NUMBERS_AVERAGE, '.2f')) 

        FILE.close()

    except (ValueError,IOError) as err:
        print(err)

except cannot be used without try.

There are two things wrong here. First, You need parenthesis to enclose the errors:

except (ValueError,IOError) as err:

See a demonstration below:

>>> try:
...     1/0
... except Exception,Exception as e:
  File "<stdin>", line 3
    except Exception,Exception as e:
                                ^
SyntaxError: invalid syntax
>>> try:
...     1/0
... except (Exception, Exception) as e:
...     print e
...
integer division or modulo by zero
>>>

Second, you need a try to go with that except line:

def average():
    try:
        TOTAL_VALUE = 0
        FILE = open("Numbers.txt", 'r')

        for line in FILE:
            AMOUNT = float(line)
            TOTAL_VALUE += AMOUNT
            NUMBERS_AVERAGE = TOTAL_VALUE / AMOUNT
        print("the average of the numbers in 'Numbers.txt' is :",
            format(NUMBERS_AVERAGE, '.2f')) 

        FILE.close()

    except (ValueError,IOError) as err:
        print(err)

except cannot be used without try.

There are two things wrong here. First, You need parenthesis to enclose the errors:

except (ValueError,IOError) as err:

Second, you need a try to go with that except line:

def average():
    try:
        TOTAL_VALUE = 0
        FILE = open("Numbers.txt", 'r')

        for line in FILE:
            AMOUNT = float(line)
            TOTAL_VALUE += AMOUNT
            NUMBERS_AVERAGE = TOTAL_VALUE / AMOUNT
        print("the average of the numbers in 'Numbers.txt' is :",
            format(NUMBERS_AVERAGE, '.2f')) 

        FILE.close()

    except (ValueError,IOError) as err:
        print(err)

except cannot be used without try.

Post Undeleted by CommunityBot
added 574 characters in body
Source Link
user2555451
user2555451

There are two things wrong here. First, You need parenthesis to enclose the errors:

except (ValueError, IOError) as err:

See a demonstration below:

>>> try:
...     1/0
... except Exception, Exception as e:
  File "<stdin>", line 3
    except Exception, Exception as e:
                                ^
SyntaxError: invalid syntax
>>> try:
...     1/0
... except (Exception, Exception) as e:
...     print e
...
integer division or modulo by zero
>>>

Second, you need a try to go with that except line:

def average():
    try:
        TOTAL_VALUE = 0
        FILE = open("Numbers.txt", 'r')

        for line in FILE:
            AMOUNT = float(line)
            TOTAL_VALUE += AMOUNT
            NUMBERS_AVERAGE = TOTAL_VALUE / AMOUNT
        print("the average of the numbers in 'Numbers.txt' is :",
            format(NUMBERS_AVERAGE, '.2f')) 

        FILE.close()

    except (ValueError,IOError) as err:
        print(err)

except cannot be used without try.

You need parenthesis to enclose the errors:

except (ValueError, IOError) as err:

See a demonstration below:

>>> try:
...     1/0
... except Exception, Exception as e:
  File "<stdin>", line 3
    except Exception, Exception as e:
                             ^
SyntaxError: invalid syntax
>>> try:
...     1/0
... except (Exception, Exception) as e:
...     print e
...
integer division or modulo by zero
>>>

There are two things wrong here. First, You need parenthesis to enclose the errors:

except (ValueError,IOError) as err:

See a demonstration below:

>>> try:
...     1/0
... except Exception,Exception as e:
  File "<stdin>", line 3
    except Exception,Exception as e:
                                ^
SyntaxError: invalid syntax
>>> try:
...     1/0
... except (Exception, Exception) as e:
...     print e
...
integer division or modulo by zero
>>>

Second, you need a try to go with that except line:

def average():
    try:
        TOTAL_VALUE = 0
        FILE = open("Numbers.txt", 'r')

        for line in FILE:
            AMOUNT = float(line)
            TOTAL_VALUE += AMOUNT
            NUMBERS_AVERAGE = TOTAL_VALUE / AMOUNT
        print("the average of the numbers in 'Numbers.txt' is :",
            format(NUMBERS_AVERAGE, '.2f')) 

        FILE.close()

    except (ValueError,IOError) as err:
        print(err)

except cannot be used without try.

Post Deleted by CommunityBot
Source Link
user2555451
user2555451

You need parenthesis to enclose the errors:

except (ValueError, IOError) as err:

See a demonstration below:

>>> try:
...     1/0
... except Exception, Exception as e:
  File "<stdin>", line 3
    except Exception, Exception as e:
                             ^
SyntaxError: invalid syntax
>>> try:
...     1/0
... except (Exception, Exception) as e:
...     print e
...
integer division or modulo by zero
>>>