Python:Lucky Seven游戏(掷骰子的平均数量)

Python:Lucky Seven游戏(掷骰子的平均数量),python,Python,我试图写一个计数函数,来计算达到0所需的转数。它返回的是diceroll+1的随机整数,如何计算myroll变量出现的次数 import random def luckysevens(): mypot = int(input("Please enter the amount of money you want to in the pot: ")) while mypot > 0: diceroll = random.randint(1, 6)

我试图写一个计数函数,来计算达到0所需的转数。它返回的是diceroll+1的随机整数,如何计算myroll变量出现的次数

import random


def luckysevens():
    mypot = int(input("Please enter the amount of money you want to in the pot: "))

    while mypot > 0:
        diceroll = random.randint(1, 6)
        print(diceroll)
        myroll = (diceroll + diceroll)
        if myroll == 7:
            mypot = mypot + 4
            print("Your roll was a 7 you earned 4$", mypot)
        else:
            mypot = mypot - 1
            print("Your roll was", myroll, "you lost 1$", mypot)
    if mypot == 0:
        print("Your out of money!")
    sum = 0
    for count in range(myroll + 1):
        sum = sum + count
    print(count)


luckysevens()

如果要计算循环退出前的转鼓数,只需添加另一个计数器变量。我还假设您正在掷骰子,所以为每个骰子添加了不同的随机调用

import random

mypot = int(input("Please enter the amount of money you want to in the pot: "))

num_rolls = 0
while mypot > 0:
    die_1 = random.randint(1,6)
    die_2 = random.randint(1,6)

    myroll = die_1 + die_2

    num_rolls += 1 # count rolls

    if myroll == 7:
        mypot = mypot + 4
        print("Your roll was a 7 you earned 4$",mypot)
    else:
        mypot = mypot - 1
        print("Your roll was",myroll,"you lost 1$",mypot)

if mypot == 0:
    print("Your out of money!")

print 'Num rolls: {}'.format(num_rolls) # print rolls

mypot一开始是什么?myroll=(diceroll+diceroll)需要什么?如果是这样的话,myroll将永远不会达到7…你想数一数掷骰子的次数吗?mypot是一个输入,我正在尝试数一数掷骰子的次数。在这个程序中有两个骰子被掷,这就是我掷骰子的原因。最初有两个不同的骰子变量,但我将其缩减为1。您需要两个不同的骰子变量,因为需要重新计算随机函数:)