(Python) Why isn't my for loop reading the last couple lines?

I'm just a beginner so I'm practicing basics and I know indentation is key and all that when writing in python but even though my indentation is correct (hopefully), it's reading it as if it's outside the loop. I know nested loops and crud make things all frizzy but I don't understand why when my indentation is fine.

f=open("output.txt","r+")
abc = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
inp = raw_input("Enter a number between 0 and 27 inclusive: ")
for i in range(int(inp)):
    print " "
    c=0
    s=""
    while c<i and c<len(abc):
        s+= abc[c]+" "
        c+=1
    c-=2
    while c>=0:
        s+= abc[c]+" "
        c-=1
    f.write(s)
    print s
print "\nAll done"
f.close()

(Ps if some of the logic is out of whack sorry. All its supposed to do is go down the alphabet like a "a aba abcba abcdcba" and so on) Thank you


Ok so it works now but I'm trying to change it to an exec file but once I did, now when I double click to run it on the console it says: line 1: syntax error near unexpected token (' line 1: f = open("output.txt","w")' logout (ps I added a f.close() and fixed the logic) but when I run it regularly on the console (aka just "python filename.py" it runs just fine. Please help :)