RE: Another Python Indentation Problem

  • From: "Nathaniel Schmidt" <nathanieljsch@xxxxxxxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Thu, 9 Jun 2011 20:06:45 +1000

Hi,

 

Made a few quick changes to attached file, they are outlined below:

 

.         "exits" does not exist, I would say that was a typo so I changed
it to "exit."

.         As stated on the list a little earlier, there is no death ()
function defined, but I'm assuming you will create that later?

.         What was wrong with your indentation was: You cannot define a
function, use 4 space indent inside the namespace and then use another two
spaces inside an if statement, you have to use 4 again.  E.G.:

# The following does not work

 

def func ():

    if statement:

      print "This failed!"

 

# This should work:

 

def func ():

    if statement:

        print "This had better work!"

 

Hope this helps,

 

Nathaniel

 

From: programmingblind-bounce@xxxxxxxxxxxxx
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Harmony Neil
Sent: Thursday, 9 June 2011 7:02 PM
To: programmingblind@xxxxxxxxxxxxx
Subject: Another Python Indentation Problem

 

Sorry to bother people on the list again. OK, I've started making a mini
text adventure thing and ran it through the command line as usual. I fixed
an error that I really should have spotted anyway (a missing quotation
mark), but it now says unexpected indentation on line 12. This is part of an
if . else statement and is at the same indentation as the if line a couple
of lines above. I changed it anyway to see if it would make a difference and
as I expected, it said invalid sintax at line 12, so I put it back to the
way it was in the first place to see if anyone else has any suggestions?

I hate indentation at times .

Attached is the file game.py

If anyone had any suggestions, feel free to reply here or offlist.

Thanks,

Harmony.

 

from sys import exit
def gold_room():
    print "This room is full of gold. How much do you wish to take?"
    next = raw_input("")
    if "1" in next or "0" in next:
        how_much = int(next)
    else:
        dead("Learn to type numbers!")
    if how_much < 50:
        print "You are not greedy. You win!"
        exit(0)
    else:
        dead("You greedy bastard!")
def bear_room():
    print """There is a bear here.
The bear is holding a bunch of honey.
He is standing in front of the door.
How are you going to move the bear?"""
    bear_moved = false
    while true:
        next = raw_input("")
        if next == "take honey":
            print "The bear slaps your face off!"
        elif next == "taunt bear" and not bear_moved:
            print "The bear has moved from in front of the door. You can go 
through it now."
            bear_moved = true
        elif next == "taunt bear" and bear_moved:
            dead("The bear gets annoyed and chews your legs off.")
        elif next == "open door" and bear_moved:
            gold_room()
        else:
            print"Command not recognized."

Other related posts: