invalid syntax - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: invalid syntax (/thread-16095.html) |
invalid syntax - davy_yg - Feb-14-2019 Hello, I get this error message: File "D:\Python\Python\bet.py", line 5 def __init__(self.total=100) ^ SyntaxError: invalid syntax [Finished in 3.4s] Any clue why? Thanks in advance. RE: invalid syntax - ichabod801 - Feb-14-2019 My best guess is that you are missing a closing parenthesis at the end of the previous line. However, I can't be sure from only one line of code. RE: invalid syntax - davy_yg - Feb-14-2019 This is the whole class: class Chips: def __init__(self.total=100) self.total = total #This can be set a default value or supplied by a user input self.bet = 0 def win.bet(self) self.total += self.bet def lose.bet(self) self.total -= self.bet RE: invalid syntax - ichabod801 - Feb-14-2019 You can't have a dot in a parameter name (self.total). It needs to be a valid token. RE: invalid syntax - davy_yg - Feb-14-2019 Even total=100 itself does not work:
class Chips: def __init__(total=100) self.total = total #This can be set a default value or supplied by a user input self.bet = 0 def win.bet(self) self.total += self.bet def lose.bet(self) self.total -= self.bet RE: invalid syntax - ichabod801 - Feb-14-2019 You also need a semi-colon at the end of each def statement line. And win.bet and lose.bet are invalid method names. I would make them win_bet and lose_bet. |