Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
invalid syntax
#1
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.
Quote
#2
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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures

Quote
#3
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
Quote
#4
You can't have a dot in a parameter name (self.total). It needs to be a valid token.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures

Quote
#5
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
Quote
#6
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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures

Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  ValueError: invalid literal for int() with base 10: '' ivinjjunior 6 111 Apr-20-2019, 05:37 PM
Last Post: keames
  trace invalid pointer simon149 7 103 Apr-16-2019, 07:05 AM
Last Post: simon149
  TreeTagger : parameter file invalid : english.par Raph0909 0 86 Apr-12-2019, 12:12 PM
Last Post: Raph0909
  Invalid Syntax Error jaycuff13 1 93 Apr-07-2019, 10:34 AM
Last Post: Yoriz
  Invalid Syntax Error jaycuff13 2 154 Mar-31-2019, 09:53 AM
Last Post: jaycuff13
  I get this when trying to install a module - SyntaxError: invalid syntax ? ejected 2 88 Mar-25-2019, 07:53 PM
Last Post: ejected
  what am i doing wrong? i have SyntaxError: invalid syntax whatloop 3 158 Mar-07-2019, 12:56 AM
Last Post: snippsat
  Invalid Syntax HekticEz 3 117 Mar-04-2019, 04:39 PM
Last Post: HekticEz
  invalid syntax near break synthex 2 144 Feb-23-2019, 11:57 AM
Last Post: synthex
  Invalid parameter - Please help maligmus 1 153 Feb-07-2019, 09:29 AM
Last Post: buran

Forum Jump:


Users browsing this thread: 1 Guest(s)