-3

I am learning to make a role playing game in Python by watching some tutorials on Youtube. The guy didn't show me how to setup anything to get it working. I did get pygame and stuff working by watching other videos. Anyway here is my error and code:

#!C:\python32
class Character:
def __init__(self, name, hp):
    self.name = name
    self.hp = hp

c = Character("Test", 5)
print c.name
print c.hp

Error:

File "C:\Users\Johnathan\Desktop\My Game\character\character.py", line 8
print c.name
^ SyntaxError: invalid syntax
[Finished in 0.2s with exit code 1]

0

1 Answer 1

1

In python3 print is a function, not a statement.

Try:

print(c.name)

Also you are missing an indentation after class Character:. (Rule of thumb: After most colons follows either a single statement on the same line, or an indented suite of statements.) Your code should read:

class Character:
    def __init__(self, name, hp):
        self.name = name
        self.hp = hp

c = Character("Test", 5)
print(c.name)
print(c.hp)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.