【发布时间】:2018-01-03 20:36:16
【问题描述】:
我正在用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。我想要它做的是乘以 不同 整数的数量并将它们加在一起。
【问题讨论】:
标签: python-3.x simulator dice