RE: Another Python Indentation Problem

  • From: "Homme, James" <james.homme@xxxxxxxxxxxx>
  • To: "programmingblind@xxxxxxxxxxxxx" <programmingblind@xxxxxxxxxxxxx>
  • Date: Thu, 9 Jun 2011 10:58:34 -0400

Hi Harmony,
I just was reading in the Python documentation that if you use -t as a command 
line option when you compile and run, that it will warn you if you are using 
tab characters instead of spaces for indentation. If you use -tt, it will 
produce errors. I found this when I was looking for a compile only option.

Jim

From: programmingblind-bounce@xxxxxxxxxxxxx 
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Harmony Neil
Sent: Thursday, June 09, 2011 10:34 AM
To: programmingblind@xxxxxxxxxxxxx
Subject: RE: Another Python Indentation Problem

Thanks for that Ken. I wondered why I was getting errors about that bit. I'm 
going to make more code now. *smiles*

From: programmingblind-bounce@xxxxxxxxxxxxx 
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Ken Perry
Sent: 09 June 2011 14:09
To: programmingblind@xxxxxxxxxxxxx
Subject: RE: Another Python Indentation Problem

By the way Harmony.  Your function works but it has errors if people type 
things like arg5 instead of a number  or for that matter it has other problems. 
 The following is what I did to fix it.  Oh if you want I can send it as an 
attachment to.

from sys import exit
def gold_room():
    print "This room is full of gold. How much do you wish to take?"
    next = raw_input("?")

    try:
        how_much = int(next)
    except:
        how_much=-1

    if how_much<0:
        print "Learn to type numbers!"
    elif how_much < 50:
        print "You are not greedy. You win!"
        exit(0)
    else:
        print "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."

gold_room()



From: programmingblind-bounce@xxxxxxxxxxxxx 
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Harmony Neil
Sent: Thursday, June 09, 2011 8:53 AM
To: programmingblind@xxxxxxxxxxxxx
Subject: RE: Another Python Indentation Problem

I've changed the bitd that say dead so they say print. I just tried running the 
file again and it decides to do ... nothing. The annoying thing is, it doesn't 
show that there are any errors with the file either.


From: programmingblind-bounce@xxxxxxxxxxxxx 
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Nathaniel Schmidt
Sent: 09 June 2011 11:07
To: programmingblind@xxxxxxxxxxxxx
Subject: RE: Another Python Indentation Problem

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.


________________________________
This e-mail and any attachments to it are confidential and are intended solely 
for use of the individual or entity to whom they are addressed. If you have 
received this e-mail in error, please notify the sender immediately and then 
delete it. If you are not the intended recipient, you must not keep, use, 
disclose, copy or distribute this e-mail without the author's prior permission. 
The views expressed in this e-mail message do not necessarily represent the 
views of Highmark Inc., its subsidiaries, or affiliates.

Other related posts: