Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何将我的CRAP代码的输出添加到数组中?_Python_Arrays_Python 3.x - Fatal编程技术网

Python 如何将我的CRAP代码的输出添加到数组中?

Python 如何将我的CRAP代码的输出添加到数组中?,python,arrays,python-3.x,Python,Arrays,Python 3.x,如何将CRAP代码的输出添加到数组my_列表中? 我希望最终输出如下所示: 1's: {No. Of One's} 2's: {No. Of Two's} 3's: {No. Of Three's} 4's: {No. Of Four's} 显然,在它打印游戏输出之后 我尝试将append-to-array行添加到底部,然后使用print-my-u列表来执行此操作,这样它就可以运行了,但是这不起作用 我的代码如下所示: my_list = [] for i in range(1,2):

如何将CRAP代码的输出添加到数组my_列表中? 我希望最终输出如下所示:

1's: {No. Of One's}
2's: {No. Of Two's}
3's: {No. Of Three's}
4's: {No. Of Four's}
显然,在它打印游戏输出之后 我尝试将append-to-array行添加到底部,然后使用print-my-u列表来执行此操作,这样它就可以运行了,但是这不起作用

我的代码如下所示:

my_list = []
for i in range(1,2):
    def RollDice():
        import random
        d1 = random.randint(1, 6)
        d2 = random.randint(1, 6)
        return int(d1 + d2)


    def ComeOutRoll():
        print('Come-Out Roll')
        roll = RollDice()
        if roll in [7, 11]:
            print('You win!')
        elif roll in [2,3,12]:
            # craps lose
            print('Craps! You lose!')
        elif roll in [4,5,6,8,9,10]:
            # the point
            print('Point %d' % roll)
            Finished = False
            while not Finished: Finished = ReRoll(roll)

    def ReRoll(point):
        roll = RollDice()
        print(' Roll: %d' % (roll))
        if not roll in [7, point]:
            # lose
            print('Roll again!')
        elif roll in [point]:
            # point match
            print('Point-Match')
        elif roll in [7]:
            # seven-out lose
            # game over
            print('Seven-Out!\nYou lose!\nGame Over!')
            return True
        return False

    ComeOutRoll()
    my_list.append(RollDice)
print(my_list)

Output:

Come-Out Roll
You win!
[<function RollDice at 0x000000CAEFAAFAE8>]
my_list=[]
对于范围(1,2)内的i:
def RollDice():
随机输入
d1=随机的随机数(1,6)
d2=random.randint(1,6)
返回整数(d1+d2)
def ComeOutRoll():
打印(“输出卷”)
roll=RollDice()
如果滚入[7,11]:
打印(“你赢了!”)
elif滚入[2,3,12]:
#掷骰子输
打印(“废话!你输了!”)
elif滚入[4,5,6,8,9,10]:
#重点
打印('点%d'%1!')
完成=错误
未完成时:完成=重新滚动(滚动)
def重新滚动(点):
roll=RollDice()
打印('卷:%d'(卷))
如果没有滚入[7,点]:
#失去
打印('再次滚动!')
elif滚入[点]:
#积分赛
打印('点匹配')
elif滚入[7]:
#七胜一负
#游戏结束
打印('7-Out!\n您输了!\n结束!')
返回真值
返回错误
出场人数()
我的列表。附加(滚动骰子)
打印(我的列表)
输出:
出卷
你赢了!
[]
试试这个

my_list = []
my_num = []
for i in range(1,2):
def RollDice():
    import random
    d1 = random.randint(1, 6)
    d2 = random.randint(1, 6)
    UpdArray(d1)
    UpdArray(d2)
    return int(d1+d2)
def UpdArray(x):
    my_num.append(x)
def ComeOutRoll():
    print('Come-Out Roll')
    roll = RollDice()
    if roll in [7, 11]:
        print('You win!')
    elif roll in [2,3,12]:
        # craps lose
        print('Craps! You lose!')
    elif roll in [4,5,6,8,9,10]:
        # the point
        print('Point %d' % roll)
        Finished = False
        while not Finished: Finished = ReRoll(roll)

def ReRoll(point):
    roll = RollDice()
    print(' Roll: %d' % (roll))
    if not roll in [7, point]:
        # lose
        print('Roll again!')
    elif roll in [point]:
        # point match
        print('Point-Match')
    elif roll in [7]:
        # seven-out lose
        # game over
        print('Seven-Out!\nYou lose!\nGame Over!')
        return True
    return False

ComeOutRoll()
my_list.append(RollDice())
print(my_list)
print("req. ", my_num)

for x in set(my_num):
    print(x,"'s", my_num.count(x), "\n" )
样本输出:

Come-Out Roll
Point 10
Roll: 7
Seven-Out!
You lose!
Game Over!
[9]
req. [4, 6, 6, 1, 3, 6]
1 's 1
3 's 1
4 's 1
6 's 3
试试这个

my_list = []
my_num = []
for i in range(1,2):
def RollDice():
    import random
    d1 = random.randint(1, 6)
    d2 = random.randint(1, 6)
    UpdArray(d1)
    UpdArray(d2)
    return int(d1+d2)
def UpdArray(x):
    my_num.append(x)
def ComeOutRoll():
    print('Come-Out Roll')
    roll = RollDice()
    if roll in [7, 11]:
        print('You win!')
    elif roll in [2,3,12]:
        # craps lose
        print('Craps! You lose!')
    elif roll in [4,5,6,8,9,10]:
        # the point
        print('Point %d' % roll)
        Finished = False
        while not Finished: Finished = ReRoll(roll)

def ReRoll(point):
    roll = RollDice()
    print(' Roll: %d' % (roll))
    if not roll in [7, point]:
        # lose
        print('Roll again!')
    elif roll in [point]:
        # point match
        print('Point-Match')
    elif roll in [7]:
        # seven-out lose
        # game over
        print('Seven-Out!\nYou lose!\nGame Over!')
        return True
    return False

ComeOutRoll()
my_list.append(RollDice())
print(my_list)
print("req. ", my_num)

for x in set(my_num):
    print(x,"'s", my_num.count(x), "\n" )
样本输出:

Come-Out Roll
Point 10
Roll: 7
Seven-Out!
You lose!
Game Over!
[9]
req. [4, 6, 6, 1, 3, 6]
1 's 1
3 's 1
4 's 1
6 's 3

你想知道骰子掷一个特定数字的次数吗?你是在列表中添加方法,而不是调用它的结果(你缺少括号)。我想打印出每个数字的打印次数,例如,打印1:4,就像数字1被使用了4次一样。我如何解决这个问题?Sorry你想知道骰子掷一个特定数字的次数吗?你是在列表中添加方法,而不是调用它的结果(你缺少括号)。我想打印出每个数字的打印次数,例如,打印1:4,就像数字1被使用了4次一样。我如何解决这个问题?Sorry这可能是我的错,我喜欢它这样它可以打印程序在一个collumn中滚动的每个数字中有多少个所以:1ns:32:4 ect但在彼此之下这可能是我的错,我喜欢它这样它可以打印程序在一个collumn中滚动的每个数字中有多少个所以:1ns:32:4 ect但在彼此之下