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 JSON payload received. Unknown name “”: Root element must be a message." hellraiser 1 63 8 hours ago
Last Post: scidam
  ValueError: invalid literal for int() with base 10: '' Jay123 7 207 Aug-05-2019, 02:43 PM
Last Post: Jay123
  SyntaxError: invalid character in identifier neogeo 2 112 Jul-27-2019, 11:11 AM
Last Post: neogeo
  SyntaxError: invalid character in identifier ricardodepaula 2 101 Jul-25-2019, 09:20 PM
Last Post: ricardodepaula
  SyntaxError: invalid syntax jurg1505 5 219 Jul-14-2019, 03:30 PM
Last Post: ichabod801
  Invalid archive error when attempting to install dash bootstrap components meaydemi 0 273 Jul-11-2019, 05:49 PM
Last Post: meaydemi
  SyntaxError: invalid syntax Truman 7 4,137 Jun-16-2019, 04:54 PM
Last Post: apollo
  ValueError: invalid rectstyle object fen1c5 1 343 Jun-05-2019, 02:51 PM
Last Post: heiner55
  Why do i have invalid syntax on a line after print, i see no error ? iofhua 5 253 May-24-2019, 05:42 PM
Last Post: Yoriz
  invalid syantx metro779966 3 341 Apr-26-2019, 03:00 PM
Last Post: keames

Forum Jump:


Users browsing this thread: 1 Guest(s)