【发布时间】:2021-04-19 11:34:44
【问题描述】:
这里是 Python 初学者
将投注游戏作为 OOP 练习的一部分。
制作了一个带有下注功能的 Player 类:
# Player Class
class Player():
def __init__(self,name):
self.name = name
self.hand = []
self.chips = 0
def deposit(self,amount):
self.chips += int(amount)
print(f"{amount} chips deposited.\nTotal available funds: {self.chips}")
def bet(self):
amount = int(input("Place your bet: "))
if not amount > self.chips:
self.chips -= amount
print(f"You bet {amount}. New Balance: {self.chips}")
return amount
else:
print("You cannot bet above your chips")
我的印象是类中的方法充当函数,但是“return amount”命令返回“None/NoneType”。
如何返回要添加的整数值以分配给变量?
提前致谢
【问题讨论】:
标签: python oop methods return-type