骰子滚动模拟器

Dice Rolling Simulator

我正在 python 制作一个骰子滚动模拟器来玩 dnd。我是 python 的新手,所以如果我的代码真的很糟糕,请不要取笑我。

import random
while 1 == 1:
    dice = input("What kind of dice would you like to roll?: ") # This is asking what kind of dice to roll (d20, d12, d10, etc.)
    number = int(input("How many times?: ")) # This is the number of times that the program will roll the dice
    if dice == 'd20':
        print(random.randint(1,21) * number)
    elif dice == 'd12':
        print(random.randint(1,13) * number)
    elif dice == 'd10':
        print(random.randint(1,11) * number)
    elif dice == 'd8':
        print(random.randint(1,9) * number)
    elif dice == 'd6':
        print(random.randint(1,7) * number)
    elif dice == 'd4':
        print(random.randint(1,5) * number)
    elif dice == 'd100':
        print(random.randint(1,101) * number)
    elif dice == 'help':
        print("d100, d20, d12, d10, d8, d6, d4, help, quit")
    elif dice == 'quit':
        break
    else:
        print("That's not an option. Type help to get a list of different commands.")

quit()

我本来的注意力只是顺其自然,不做一个数字变量,后来我哥提醒我,有些武器有多次滚动,而不是只滚动一次以上,我想有一个输入,问如何多次掷骰子。我的代码现在的问题是它会将数字随机化,然后 然后 乘以 2。我想要它做的是乘以 不同 整数的数量并将它们相加。

也许使用 for 循环并迭代用户想要掷骰子的 number 次,同时将这些保存到列表中以显示每次掷骰子。

例如,第一个骰子可能如下所示:

rolls = []
if dice == 'd20':
    for roll in range(number):
        rolls.append(random.randint(1,21))
    print('rolls: ', ', '.join([str(roll) for roll in rolls]))
    print('total:', sum(rolls))

示例输出:

What kind of dice would you like to roll?: d20
How many times?: 2
rolls:  10, 15
total: 25
import random

print("Rolling the Dice....")
dice_number = random.randint(1, 6)
print(dice_number)
limit = 0
while limit <= 4:

    ask = input("Would you like to roll again?? Yes or No ").upper()
    limit = limit + 1
    if ask == "YES":
        print(random.randint(1, 6))
    elif ask == "NO":
        print("Thank You.")
        break
    else:
        print("Thank You.")
        break
 else:
    print("Limit Reached..TRY AGAIN!!")