gpt4 book ai didi

Python 类型错误 : unorderable types: builtin_function_or_method() < int()

转载 作者:行者123 更新时间:2023-12-01 04:43:25 27 4
gpt4 key购买 nike

我在尝试执行 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

while (input <= 1):

您是想这样做吗?

while (num_rolls > 0):

关于Python 类型错误 : unorderable types: builtin_function_or_method() < int(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30032000/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com