
December 24th, 2012, 03:27 PM
|
|
Registered User
|
|
Join Date: Oct 2012
Posts: 8
Time spent in forums: 4 h 58 m 58 sec
Reputation 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.")
|