By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,965 Members | 1,631 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,965 IT Pros & Developers. It's quick & easy.

Begniner Question

P: n/a
#!/usr/local/bin/python

import sys

print "1.\tDo Something"
print "2.\tDo Something"
print "3.\tDo Something"
print "4.\tDo Something"
print "5.\tDo Something"
print "6.\tExit"

choice=raw_input("Please Enter Choice: ")

if int(choice)==1:
print "Here"
else:
pass

if int(choice)==2:
else:
pass

if int(choice)==3:
else:
pass

if int(choice)==4:
else:
pass

if int(choice)==5:
else:
pass

if int(choice)==6:
sys.exit(0)
else:
pass

File "./Code.py", line 20
else:
^
IndentationError: expeted an indented block

What am I doing wrong?

Thank-you
Jul 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a

"Glen" <kg**@tpg.com.au> wrote in message news:42******@dnews.tpgi.com.au...
if int(choice)==2:
else:
pass

File "./Code.py", line 20
else:
^
IndentationError: expeted an indented block

What am I doing wrong?


As the error trace informs you, Python expexts an indented block. You need
to put something between if and else, at least a pass.

Regards

--
/Mikael Olofsson
Universitetslektor (Senior Lecturer [BrE], Associate Professor [AmE])
Linköpings universitet

-----------------------------------------------------------------------
E-Mail: mi****@isy.liu.se
WWW: http://www.dtr.isy.liu.se/en/staff/mikael
Phone: +46 - (0)13 - 28 1343
Telefax: +46 - (0)13 - 28 1339
-----------------------------------------------------------------------
Linköpings kammarkör: www.kammarkoren.com Vi söker tenorer och basar!

Jul 18 '05 #2

P: n/a
Glen wrote:
#!/usr/local/bin/python

import sys

print "1.\tDo Something"
print "2.\tDo Something"
print "3.\tDo Something"
print "4.\tDo Something"
print "5.\tDo Something"
print "6.\tExit"

choice=raw_input("Please Enter Choice: ")

if int(choice)==1:
print "Here"
else:
pass

if int(choice)==2:
else:
pass


You need something between the if: and the else: lines.

--
Robert Kern
rk***@ucsd.edu

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
Jul 18 '05 #3

P: n/a
Glen wrote:
#!/usr/local/bin/python

import sys

print "1.\tDo Something"
print "2.\tDo Something"
print "3.\tDo Something"
print "4.\tDo Something"
print "5.\tDo Something"
print "6.\tExit"

choice=raw_input("Please Enter Choice: ")

if int(choice)==1:
print "Here"
else:
pass

if int(choice)==2:
else:
pass
(snip)
File "./Code.py", line 20
else:
^
IndentationError: expeted an indented block

What am I doing wrong?
Err... I'm not totally sure, but I think it could be possible that you
perhaps should insert an indented block between lines 19 and 20 !-)
Thank-you

You're welcome !-)

A bit more seriously, now... the construct:

if some_condition:
else:
pass

is syntactically incorrect. Python expects an indented block between the
'if' line and the 'else' line. If you don't have the needed code yet,
you need to put a 'pass' here :

if some_condition:
pass
else:
pass

This will of course do nothing else than useless tests, but it will at
least satisfy the language's rules.

--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom.gro'.split('@')])"
Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.