Begniner Question

G

Glen

#!/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
 
M

Mikael Olofsson

Glen said:
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
 
R

Robert Kern

Glen said:
#!/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
(e-mail address removed)

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
 
B

bruno modulix

Glen said:
#!/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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,222
Messages
2,571,142
Members
47,775
Latest member
MadgeMatti

Latest Threads

Top