def Reset():
global seven_digit
seven_digit = ["","","","","","",""]
global x
x = 0
global eight
eight = 0
global c
c = 0
cinput()
def cinput():
global thing
print("Enter digit ", x+1)
thing = input("")
check()
def check():
global eight
global x
if not thing.isdigit():
print("That character is not allowed")
cinput()
elif len(thing) > 1:
print("Those characters are not allowed")
cinput()
if x < 7:
seven_digit[x] = int(thing)
x += 1
cinput()
if x == 7:
eight = int(thing)
fcheck()
def fcheck(): #this section is temporary just for testing
global c
c+=1
print("This is c, ", c)
print("Test")
print(seven_digit)
print(eight)
Reset()
这是我作为一个级别任务开发的代码(这是今年的GCSE课程)然而我偶然发现了一个问题,其中fcheck()的自创函数的最后一部分重复了8次。我之前在python中使用过类似的过程,我以前从未见过类似的错误。我想知道是否有人知道我能做些什么来解决它,谢谢。
答案 0 :(得分:1)
check
和cinput
之间存在相互呼叫,因此,您在此调用链中调用fcheck
,将被调用8次。
如果您想在所有评估链之后调用fcheck
一次,您可以在check
的最后一行删除对它的调用,并在{{1}的末尾调用它}}:
Reset