- #1
clope023
- 992
- 131
Hello, the title says it all; I am trying to teach myself Python using version 2.7.1 aka matplotlib or PYLAB via the MIT opencourseware as well as the tutorial from the site I downloaded it from; I am having a very frustrating time using it as system continues to return any variant of else statements as syntax errors.
An attempted example program is as follows:
x = 2
if (x/2)*2 == x:
... print 'Even'
... else: print 'Odd'
...
...
'Even'
This would be my expected output but, python continues to give me a syntax error whenever I use the else statement. I've tried it without the colons, I've tried added the else's command on another line, I've tried using the elif function and nothing works the editor contiues to give syntax errors.
I know I'm using the correct code as I am pulling several examples from the tutorial and they've all been correct except this one. Does python 2.7.1 not recognize else statements? Does anyone know if the syntax has changed? Does anyone know the correct syntax? Any and all help is greatly appreciated.
An attempted example program is as follows:
x = 2
if (x/2)*2 == x:
... print 'Even'
... else: print 'Odd'
...
...
'Even'
This would be my expected output but, python continues to give me a syntax error whenever I use the else statement. I've tried it without the colons, I've tried added the else's command on another line, I've tried using the elif function and nothing works the editor contiues to give syntax errors.
I know I'm using the correct code as I am pulling several examples from the tutorial and they've all been correct except this one. Does python 2.7.1 not recognize else statements? Does anyone know if the syntax has changed? Does anyone know the correct syntax? Any and all help is greatly appreciated.
Last edited: