Python类型错误:不可比较的类型:内置函数或方法() < int()

2024-06-25 05:18:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在尝试做一个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()

Tags: of程序numberinputrandomnuminttotal