Python Forum

Full Version: invalid syntax
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.
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.
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
You can't have a dot in a parameter name (self.total). It needs to be a valid token.
Even total=100 itself does not work:

Error:
[python] File "D:\Python\Python\bet.py", line 8 def __init__(total=100) ^ SyntaxError: invalid syntax
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
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.