首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么我的player.bet得不到任何东西

为什么我的player.bet得不到任何东西
EN

Stack Overflow用户
提问于 2021-07-12 01:41:51
回答 1查看 25关注 0票数 0
代码语言:javascript
复制
class inputs:
    def bet(self):
        """
        takes in the bet from the user and stores it in the player class
        :return: output
        """
        self.bet = input("Enter the amount for your bet : ")
        output = self.bet
        if self.bet.isnumeric() == False:
            print("Use your monke brains and enter correct input")
            inputs.bet(self)
        else:
            return output
    def Aval(self):
        """
        Takes the value for ace and stores it in the player class
        :return: output
        """
        self.aval = input("Enter the value for ACE (1 or 10) : ")
        output = self.aval
        if self.aval.isnumeric() == False:
            print("Use your monke brains and enter correct input")
            inputs.Aval(self)
        elif self.aval.isnumeric() == True:
            if self.aval in ["1", "10"]:
                return output
            else:
                print("I understand you suffer braincell deficiency but I need you to fire up those 2 braincells you have and enter the proper number")
                inputs.Aval(self)
class Player:
    deck = ["A♣", "2♣", "3♣", "4♣", "5♣", "6♣", "7♣", "8♣", "9♣", "10♣", "J♣", "K♣", "Q♣", "A♦", "2♦", "3♦", "4♦", "5♦",
            "6♦", "7♦", "8♦", "9♦", "10♦", "J♦", "K♦", "Q♦", "A♥", "2♥", "3♥", "4♥", "5♥", "6♥", "7♥", "8♥", "9♥",
            "10♥", "J♥", "K♥", "Q♥", "A♠", "2♠", "3♠", "4♠", "5♠", "6♠", "7♠", "8♠", "9♠", "10♠", "J♠", "K♠", "Q♠"]

    total = 0
    def __init__(self):
        self.name = input("Enter your name : ")
        self.bet = inputs.bet(self)
        self.Aval = inputs.Aval(self)

p = Player()
print(p.bet)
print(p.aval)

如果您输入错误的输入,inputs.bet()函数会运行2-3次,为什么对于p.bet我会得到None

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-07-12 10:51:02

bet中,当用户需要重试时,您需要返回最终成功的输入。

代码语言:javascript
复制
        if self.bet.isnumeric() == False:
            print("Use your monke brains and enter correct input")
            return inputs.bet(self)
         #  ^^^ add this
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68338641

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档