【发布时间】:2014-04-01 17:20:10
【问题描述】:
在下面的代码中,我想添加一些内容,当用户输入除 4、6 或 12 之外的任何内容时会向用户发送错误消息:
import random
dice = input("""Hello there!
Welcome to the dice roll simulator.
There are three types of dice which you can roll:
a 4 sided die, a 6 sided die and a 12 sided die.
Please enter either 4,6 or 12 depending on which die you would like to roll.""")
if dice : 4 or 6 or 12
print("You have rolled a " + dice + " sided dice, with the result of : " + str((random.randrange(1,int(dice)))))
【问题讨论】:
-
您需要先将输入结果转换为整数:
dice = int(dice) -
我想我以前从未在 SO 上看到这么多重复的答案。
标签: python