【发布时间】:2015-12-27 09:55:18
【问题描述】:
我是 Python 新手,在开发 D&D Dice 程序时遇到了一些问题。
import random
print("Hi,here you can roll all D´n´D Dice´s!")
dice=input("What dice do u want?D4,D6,D8,D10,D12,D20 or D100?")
if dice=="D4" or "d4":
print(random.randint(1,4))
elif dice=="D6" or "d6":
print(random.randint(1,6))
elif dice=="D8" or "d8":
print(random.randint(1,8))
elif dice=="D10"or"d10":
print(random.randint(1,10))
elif dice=="D12"or"d12":
print(random.randint(1,12))
elif dice=="D20"or"d20":
print(random.randint(1,20))
elif dice=="D100"or"d100":
print(random.randint(1,100))
else: print("No?Ok!")
当我运行程序并输入骰子的数量时,它总是输入第一个if语句。
【问题讨论】:
-
你总是得到一个从 1 到 4 的数字(正如 Baruchel 的回答所修正的那样),还是你总是得到数字 1?另外,如果输入无效的输入(例如,
D3?)会得到什么
标签: python python-3.5