-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]

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

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)
Hyperboreus
  • 31,997
  • 9
  • 47
  • 87