My name is Piyush and I have just started learning to code in python. Right now I am working on a project. And would really appreciate if anyone can help in adding customized parameters in functions. I am mentioning my code and the problem I am facing down below:
class Chips ():
def __init__ (self, total):
while True:
try:
total = int(input("How many chips as total?: ?"))
except:
print("Please enter an integer")
else:
break
self.total = total
self.bet = 0
def win_bet (self):
self.total = self.total + self.bet
def loose_bet (self):
self.total = self.total - self.bet
However, I can set total = 100 and can run the game but I want the user to be able to enter the total chips he/she wants to add.
I want the input(total) in the while loop to be as the argument while running the game. But I keep on getting this error:
--
TypeError Traceback (most recent call last)
<ipython-input-9-b1b7b1c195f7> in <module>()
367
368 # Set up the Player's chips
--> 369 player_chips = Chips() # remember the default value is 100
370
371 # Prompt the Player for their bet:
TypeError: __init__() missing 1 required positional argument: 'total'
Please Help!
Thanks for your attention to my request.
totaltoChips:Chips(total). Don't ask for input inside__init__. Instead, callint(input())outsideChipsand pass the result.elseclause, a nicer way is to put the break right after the line that might excepttotal = int(...in your case.