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
  Invalid parameter - Please help maligmus 1 58 Feb-07-2019, 09:29 AM
Last Post: buran
  Invalid Identifier In Long Text File asilverg 1 79 Jan-25-2019, 11:59 PM
Last Post: ichabod801
  Invalid syntax on input string Callahan 5 254 Nov-01-2018, 06:37 PM
Last Post: buran
  Invalid syntax in two variable if statement? 00712411 1 263 Oct-10-2018, 12:36 AM
Last Post: stullis
  "invalid syntax" for no apparent reason wardancer84 2 303 Oct-03-2018, 11:57 AM
Last Post: wardancer84
  [split] invalid syntax MasterScythe 3 280 Sep-27-2018, 01:42 PM
Last Post: Larz60+
  "Invalid Syntax" (I am a new coder) Marius2002 8 551 Sep-08-2018, 06:39 AM
Last Post: Marius2002
  def function SyntaxError: invalid syntax Said 1 715 Jul-10-2018, 10:16 AM
Last Post: Said
  Invalid Syntax Error on Import arjunsingh2908 3 696 Jul-07-2018, 05:02 PM
Last Post: ichabod801
  invalid syntax lokchi2017 1 317 Jul-05-2018, 09:55 AM
Last Post: buran

Forum Jump:


Users browsing this thread: 1 Guest(s)