Pyhon 3.3.3 on windows 7: else command

A forum for general discussion of the Python programming language.

Pyhon 3.3.3 on windows 7: else command

Postby susovan » Thu Jan 30, 2014 3:49 pm

Hello,

I'm using python 3.3.3. on windows 7. The if...: statement works fine, but else: seems to give me a syntax error. Let me copy and paste here:

Code: Select all
>>> temp=70
>>> if temp>60 and temp<80:
   print('nice temp')
   else
   
SyntaxError: invalid syntax
>>>


Why did this occur? I also tried putting a semi-colon (;) after print('nice temp'), but it didn't work. How can I correct this? Thanks!
susovan
 
Posts: 2
Joined: Thu Jan 30, 2014 3:36 pm

Re: Pyhon 3.3.3 on windows 7: else command

Postby stranac » Thu Jan 30, 2014 3:52 pm

You need a colon after else.

Also, please read this to learn how to post code: viewtopic.php?t=145
I tried fixing your code, but it still seems broken.
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1246
Joined: Thu Feb 07, 2013 3:42 pm

Re: Pyhon 3.3.3 on windows 7: else command

Postby Kebap » Thu Jan 30, 2014 3:53 pm

Welcome! :)

Doesn't seem like a problem about your python version or operating system.

Just add a : after else

Code: Select all
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> if 70>60:
...   print 1
... else:
...   print 2
...
1
>>> if 70>60:
...   pass
... else
  File "<stdin>", line 3
    else
       ^
SyntaxError: invalid syntax
>>>
Learn: How To Ask Questions The Smart Way
Join the #python-forum IRC channel on irc.freenode.net and chat with uns directly!
Kebap
 
Posts: 403
Joined: Thu Apr 04, 2013 1:17 pm
Location: Germany, Europe

Re: Pyhon 3.3.3 on windows 7: else command

Postby susovan » Thu Jan 30, 2014 4:02 pm

I tried adding a colon after else as well, but it didn't seem to work.

>>> temp=70
>>> if temp>60 and temp<80:
print ('nice temp')
else:

SyntaxError: invalid syntax
>>> temp=70
>>> if temp>60 and temp<80:
print('nice temp');
else:

SyntaxError: invalid syntax
susovan
 
Posts: 2
Joined: Thu Jan 30, 2014 3:36 pm


Return to General Discussions

Who is online

Users browsing this forum: No registered users and 1 guest