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()这是我一直作为a级任务开发的代码(这是今年的GCSE课程),但是我遇到了一个问题,在自创建函数fcheck()中的最后一部分重复了8次。我以前在python中使用过类似的过程,以前从未见过这样的错误。我想知道有没有人知道我能做些什么来解决这个问题,谢谢。
发布于 2017-09-17 15:01:54
check和cinput之间有一个相互调用,所以在这个调用链中调用fcheck,它将被调用8次。
如果您想要调用fcheck一次,在所有的计算链之后,您可以在check的最后一行删除对它的调用,然后在Reset的末尾调用它。
def Reset():
global seven_digit
seven_digit = ["","","","","","",""]
global x
x = 0
global eight
eight = 0
global c
c = 0
cinput()
fcheck()
def cinput():
global thing
print("Enter digit ", x+1)
thing = str(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)
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()https://stackoverflow.com/questions/46264840
复制相似问题