【发布时间】:2016-07-01 13:03:04
【问题描述】:
我正在尝试创建一个猜谜游戏,但我遇到了一些错误,谁能帮助我?
A = A + [i]
# Define two variables which will be the end point of
# the search span
mini = 0
maxi = len(A) - 1
stepcounter = 1
find = int(input("Think of a number between 1 and 1000"))
def guessgame(find, A, mini, maxi, stepcounter):
# This calculates the value of the midpoint element
# in the list guess = (A[mini] + A[maxi]) // 2
if guess == find:
return
print("You think of", guess, "I did this in", stepcounter, "number of steps")
elif guess < find:
mini = guess
stepcounter = stepcounter + 1
guessgame(find, A, mini, maxi, stepcounter)
elif guess > find:
maxi = guess
stepcounter = stepcounter + 1
guessgame(find, A, mini, maxi, stepcounter)
else:
return
print("Not in array")
guessgame(find, A, mini, maxi, stepc
外星人)
我的错误是
traceback most recent call last:
line 34 guessgame(find, a, mini,maxi, supercounter)
File "C:/Users/Acer VN7/PycharmProjects/untitled1/py.py", line 20, in guessgame
if guess == find:
RecursionError: maximum recursion depth exceeded in comparison
【问题讨论】:
-
这可能是由于无限递归。等我重新格式化并查看代码。
-
好的,谢谢。这意味着很多
标签: python search binary binary-search-tree binary-search