Thread: Syntax Error

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    8
    Rep Power
    0

    Syntax Error


    I feel a little silly for posting this question but I keep receiving an invalid syntax message when I try to run my program.

    The line of code is:
    if points >= attributes[trib]:

    It is highlighting the colons at the end and telling me invalid syntax.

    I italicized the line in my code below, if I counted correctly it's the eighth line up from the bottom.

    What am I doing wrong here?

    Thanks!

    Code:
    #character creator program allows user to distribute attributes
    #in different areas to build up their character
    
    #the attribute points for distribution and dictionary for attributes themselves
    attpoints = 30
    attributes = {"Strength" : "0",
                  "Health" : "0",
                  "Wisdom" : "0",
                  "Dexterity" : "0"}
    
    choice = None
    
    print(
    """
    RPG Character Generator
    
    You will be given 30 attribute points to distribute as
    you see fit so that your character will be strong enough
    to vanquish evils across all the land!
    
    You can add or remove points from attribute as you see fit.
    
    """
    )
    
    while attpoints and choice != 0:
        print("\nYou have", attpoints, "points available to distribute.")
        print("Your current attributes are as follows:")
        print("\nStrength:", attributes["Strength"])
        print("Health:", attributes["Health"])
        print("Wisdom:", attributes["Wisdom"])
        print("Dexterity", attributes["Dexterity"])
        print(
        """
    
        Press 0 to QUIT
        Press 1 to add points to an attribute
        Press 2 to remove points from an attribute
         """
        )
    
        choice = input("Enter your selection: ")
        if choice == "0":
            print("\nGood-bye")
    
        elif choice == "1":
            trib = input("What attribute would you like to add points to? ")
            if trib in attributes:
                points = int(input("How many points would you like to add? "))
                if points >= attpoints:
                    print("Sorry, but you do not have that many points to")
                    print("distribute, try again...")
                else:
                    attpoints = attpoints - points
                    attributes[trib] = attributes[trib] + points
                    print("Your", trib, "is now set at", attributes[trib], "points!")
            else:
                print("That is not one of your attributes! Try again.")
    
        elif choice == "2":
            trib = input("What attribute would you like to remove points from? ")
            if trib in attributes:
                points = int(input("How many points would you like to remove? ")
                if points >= attributes[trib]:
                    print("That's too many points to take away! Try again...")
                else:
                    attpoints = points + attpoints
                    attributes[trib] = attributes[trib] - points
                    print("Your", trib, "is now set at", attributes[trib], "points!")
            else:
                print("That is not one of your attributes! Try again.")
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    10
    Rep Power
    0
    Code:
    points = int(input("How many points would you like to remove? ")
                if points >= attributes[trib]:
    you are missing a parenthesis the line above, so in essance it thinks your trying to convert everything here ^ to an int() in which causes an error upon :

    Comments on this post

    • TheLetterZero agrees
  4. #3
  5. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,702
    Rep Power
    480
    Line 63 is missing a right paren.

    points = int(input("How many points would you like to remove? ")

    python expressions span multiple lines until the parentheses are closed.

    Comments on this post

    • TheLetterZero agrees
    [code]Code tags[/code] are essential for python code and Makefiles!
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    8
    Rep Power
    0
    Ahh

    Thanks for responding to such a trivial post on Christmas Eve!
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    10
    Rep Power
    0
    what is more pathetic is that we both are on at christmas day
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    8
    Rep Power
    0
    Hah, I don't have any family down where I'm at so it's just another day to me and everything is pretty much closed so what better way to spend it than expanding my (very limited) Python knowledge?

IMN logo majestic logo threadwatch logo seochat tools logo