我正在编写一个非常简单的脚本来介绍python类。该脚本最终将为棋盘游戏Risk自动化掷骰子。它还处于早期开发阶段,但我遇到了一个我不完全理解的类型错误。这两个变量都应该是列表,因为它们是由相同的基本代码生成的,但它返回了一个类型错误。这是我到目前为止所做的代码:
print ("Please input Attacking number and defending number, in that order.")
def numdiceroll(x, y):
import random
sides = 6
attacking = x
defending = y
if attacking >= 3 and defending >= 2:
dicea = random.sample(range(1, sides + 1), 3)
print (dicea)
diced = random.sample(range(1, sides +1), 2)
print (diced)
if max(dicea) > max(diced) and min(dicea) > (diced):
print ("Attacker Wins Both")
if max(dicea) > max(diced) and min(dicea) < (diced):
print ("Both Lose 1")
if max(dicea) < max(diced) and min(dicea) > (diced):
print ("Both Lose 1")
if max(dicea) < max(diced) and min(dicea) < (diced):
print ("Defender Wins Both")
答案 0 :(得分:0)
min(dicea) > (diced)
diced
是一个列表,最小和最大返回数字。您无法将数字与列表进行比较。现在它取决于你真正想做的事情。