Invalid Syntax

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • FlamingoRider
    New Member
    • Feb 2009
    • 11

    Invalid Syntax

    I keep getting a syntax error on line 11 (while Running = True:) and I'm not sure what's going on. If this is something horribly simple I apologize. I appreciate any help.

    Code:
    myFears=" "
    def addFear():
        if len(myFears) < 1:
            print "You have not entered any fears yet. Please enter one now."
            fear=raw_input("What is a fear of yours?")
            myFears.append(fear)
        else:
            Running = True
            print "Your current fears are", myFears
            toDo=raw_input("Do you want to delete a fear, add one, or leave? (del, add, lev)")
            while Running = True:
                if toDo="add", "ADD", "Add":
                    addFear=raw_input("What is your fear?")
                    myFears.append(addFear)
                elif toDo="del","DEL","Del":
                    delFear=raw_input("What fear have you overcome?")
                    myFears.remove(delFear)
                    print "Fear has been deleted"
                elif toDo="lev","LEV","Lev":
                    print "Goodbye"
                    Running=False
    				break
                else:
                    toDo
    
    addFear()
    XP with Cream and Python 2.6
  • boxfish
    Recognized Expert Contributor
    • Mar 2008
    • 469

    #2
    The second most common programming mistake; = is the assignment operator, == is the comparison operator. Use
    Code:
    while Running == True:
    However, you don't even need the comparison. The while loop will continue as long as the condition is true, so you can just write
    Code:
    while Running:
    I hope this helps.

    Comment

    • FlamingoRider
      New Member
      • Feb 2009
      • 11

      #3
      Wow, that was easy. Thanks a lot. I feel kinda stupid for not catching that myself. Got the bugs out now just gotta tinker with it to get it working the way I need. Thanks for all the help.

      Comment

      • boxfish
        Recognized Expert Contributor
        • Mar 2008
        • 469

        #4
        I'm glad it's running. If you don't want your program to be case sensitive, then instead of writing out all the different case combinations as in
        Code:
        if toDo="add", "ADD", "Add":
        just convert the input to lowercase with the lower() function and compare it with a lowercase string:
        Code:
        if toDo.lower() == "add":
        I hope this is helpful.

        Comment

        Working...