Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/340.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.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 在If语句中,变量不会重置为0_Python - Fatal编程技术网

Python 在If语句中,变量不会重置为0

Python 在If语句中,变量不会重置为0,python,Python,第二、第三、第四等等。。我做这件事的时候: while not(bool(won)): #print(wordspec) # print("_" * wordlen) print(displayword) answer = input("Any letters?") if answer in vl.values(): print("Yes") for x_l in

第二、第三、第四等等。。我做这件事的时候:

while not(bool(won)):
    #print(wordspec)
   # print("_" * wordlen)
    print(displayword)
    answer = input("Any letters?")


    if answer in vl.values():
        print("Yes")
        for x_l in wordspec:
            print(str(spot_l)+"cha")
            if spot_l < wordlen:
                if vl[spot_l] == answer:
                    print(vl[spot_l])
                    ch[spot_l] = vl[spot_l]
                    displayword[spot_l] = ch[spot_l]

                spot_l += 1
            elif wordlen < spot_l:
                spot_l = 0
0cha
1cha
a
2cha
3cha
a
4cha
5cha
a
6cha

(我的单词有7个字符,因此是一个7次的for循环)

你输入
spot\u l==0
,它检查是否与
0
相等(你忽略它产生的
bool
,这使得这更明显是一个错误);如果您想通过赋值将其重置为
0
,则需要
spot_l=0
如果
elif
缺少
spot==wordlen
的情况,此时它将永远循环。您可能只需要
else

哎呀,而不是
elif
!我想出来了。。所以基本上


我将wordlen 好的,这根本不是你的问题,但是
whilenot(bool(won)):
在拼写
whilenot won:
时,确实是一种很难看/很慢的方法。后者完全相同(假设您没有命名内置的
bool
),并且非常简单,引导速度也更快
not
是一个运算符,不是函数,所以根本不需要括号。请欣赏,我是python初学者,我正在尽可能多地积累经验,谢谢Derek
6cha
6cha
6cha
6cha
6cha
6cha
6cha