Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python代码在不需要时重复8次 def Reset(): 全球七位数 七位=[“”,“”,“”,“”,“”,“”,“”,“”,“”,“”] 全球x x=0 全球八国集团 八=0 全球c c=0 辛普特() def cinput(): 全球事物 打印(“输入数字”,x+1) 事物=输入(“”) 检查() def check(): 全球八国集团 全球x 如果不是的话。isdigit(): 打印(“不允许使用该字符”) 辛普特() elif len(事物)>1: 打印(“不允许使用这些字符”) 辛普特() 如果x1: 打印(“不允许使用这些字符”) 辛普特() 如果x_Python - Fatal编程技术网

Python代码在不需要时重复8次 def Reset(): 全球七位数 七位=[“”,“”,“”,“”,“”,“”,“”,“”,“”,“”] 全球x x=0 全球八国集团 八=0 全球c c=0 辛普特() def cinput(): 全球事物 打印(“输入数字”,x+1) 事物=输入(“”) 检查() def check(): 全球八国集团 全球x 如果不是的话。isdigit(): 打印(“不允许使用该字符”) 辛普特() elif len(事物)>1: 打印(“不允许使用这些字符”) 辛普特() 如果x1: 打印(“不允许使用这些字符”) 辛普特() 如果x

Python代码在不需要时重复8次 def Reset(): 全球七位数 七位=[“”,“”,“”,“”,“”,“”,“”,“”,“”,“”] 全球x x=0 全球八国集团 八=0 全球c c=0 辛普特() def cinput(): 全球事物 打印(“输入数字”,x+1) 事物=输入(“”) 检查() def check(): 全球八国集团 全球x 如果不是的话。isdigit(): 打印(“不允许使用该字符”) 辛普特() elif len(事物)>1: 打印(“不允许使用这些字符”) 辛普特() 如果x1: 打印(“不允许使用这些字符”) 辛普特() 如果x,python,Python,这是我作为a级任务开发的代码(这是今年的GCSE课程),但是我遇到了一个问题,即自创函数fcheck()的最后一部分重复了8次。我以前在python中使用过类似的过程,我从未见过这样的错误。我想知道是否有人知道我能做些什么来修复它,谢谢。在check和cinput之间有一个相互调用,因此,如果你在这个调用链中调用fcheck,它将被调用8次 如果要调用一次fcheck,则在所有求值链之后,只需在check的最后一行删除对它的调用,并在Reset结束时调用它: def Reset(): g

这是我作为a级任务开发的代码(这是今年的GCSE课程),但是我遇到了一个问题,即自创函数fcheck()的最后一部分重复了8次。我以前在python中使用过类似的过程,我从未见过这样的错误。我想知道是否有人知道我能做些什么来修复它,谢谢。

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()
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()
def Reset():
全球七位数
七位=[“”,“”,“”,“”,“”,“”,“”,“”,“”,“”]
全球x
x=0
全球八国集团
八=0
全球c
c=0
辛普特()
fcheck()
def cinput():
全球事物
打印(“输入数字”,x+1)
thing=str(输入(“”)
检查()
def check():
全球八国集团
全球x
如果不是的话。isdigit():
打印(“不允许使用该字符”)
辛普特()
elif len(事物)>1:
打印(“不允许使用这些字符”)
辛普特()
如果x<7:
七位数[x]=int(事物)
x+=1
辛普特()
如果x==7:
八=整数(事物)
def fcheck():#此部分仅用于测试
全球c
c+=1
打印(“这是c,”,c)
打印(“测试”)
打印(七位数)
印刷品(八份)
重置()

check()下的代码“if elif”应该在语句-thing=input()之后移到cinput()。递归之所以发生,是因为fcheck()重复了所有全局语句,并且缺少空格或注释。我很好奇,这堵代码墙到底想做什么?@unMask,这里没有递归。有一个调用链,但这不是递归,没有函数调用本身。@JonClements此时它只意味着将输入数组的前7位数字和第8位数字分配到单独的变量“8”中。然而,当任务完成时,它意味着检查某人的卡是否有效。
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()