我一直在尝试做一个Python程序时遇到这个错误。程序的要点是继续滚动一组模具,直到用户输入小于0的数字。
import random
num_sixes = 0
num_sevens = 0
num_rolls = int(input('Enter number of rolls:\n'))
while (input <= 1):
for i in range(num_rolls):
die1 = random.randint(1,6)
die2 = random.randint(1,6)
roll_total = die1 + die2
#Count number of sixes and sevens
if roll_total == 6:
num_sixes = num_sixes + 1
if roll_total == 7:
num_sevens = num_sevens + 1
print('Roll %d is %d (%d + %d)' % (i, roll_total, die1, die2))
print('\nDice roll statistics:')
print('6s:', num_sixes)
print('7s:', num_sevens)
else:
print('Invalid number of rolls. Try again.')
这是回溯:
Traceback (most recent call last):
File "unorderable.py", line 7, in <module>
while (input <= 1):
TypeError: unorderable types: builtin_function_or_method() <= int()
您正在比较内置函数
input
是否小于或等于1你是不是打算这么做?
相关问题 更多 >
编程相关推荐