关于python 3.x:骰子滚动模拟器

Dice Rolling Simulator

我正在用python制作Dice滚动模拟器来播放dnd。 我是python的新手,所以如果我的代码真的很糟糕,请不要取笑我。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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上进行迭代,同时将这些骰子保存到列表中以显示骰子的每一卷。

例如,第一个骰子可能看起来像这样:

1
2
3
4
5
6
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))

输出示例:

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


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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!!")