2

I can't see what the invalid syntax here is, any help would be appreciated.

if alpha == "alpha":
    updatefile('Class 1 Results.csv',0,"1")

    elif Class == "2":    
        with open('Class 2 Results.csv', 'a') as f:
            file_writer = csv.writer(f, delimiter=',',lineterminator='\n')
            file_writer.writerow((name, score))sortcsv('Class 2 Results.csv', 0) 
SamH314
  • 21
  • 5
  • 1
    The indentation level is wrong. It needs to be at the same level as the `if`. Python is whitespace sensitive. – poke Mar 15 '16 at 12:26
  • Question: Are you trying to use `Class` as a variable name? Lower-case names are recommended for Python functions and variables ([see this answer](http://stackoverflow.com/q/159720/3345375)), and `class` is a [keyword](http://www.programiz.com/python-programming/keyword-list) in Python. – jkdev Mar 15 '16 at 13:08
  • 1
    In Python indentation IS part of language syntax. You need to outdent your `elif` block. – Łukasz Rogalski Mar 15 '16 at 13:12

1 Answers1

3

Try this:

if alpha == "alpha":
    updatefile('Class 1 Results.csv',0,"1")
elif Class == "2":
    with open('Class 2 Results.csv', 'a') as f:
        file_writer = csv.writer(f, delimiter=',',lineterminator='\n')
        file_writer.writerow((name, score))sortcsv('Class 2 Results.csv', 0)

As mentioned in @poke's comment, whitespace is significant in Python. That's why the indentation has to be correct -- for example, in an if statement, the if, elif, and else must all be at the same level of indentation.

jkdev
  • 11,360
  • 15
  • 54
  • 77