Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.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 新列表输入不更新函数结果_Python_List_Function - Fatal编程技术网

Python 新列表输入不更新函数结果

Python 新列表输入不更新函数结果,python,list,function,Python,List,Function,我是python新手,最近开始了这个项目。我觉得我很接近,但我不知道为什么我的值在输入一组新的数字时不会更新?我认为这是最后一个函数中的一个问题。图片描述: def cow_bull(): 游戏=真实 idx=0 cow=0#在错误的位置正确地猜到了麻木 bull=0#猜测正确,麻木在正确的位置 计数=1 尽管如此: n=(玩家列表(“输入你的猜测:”) 当idx

我是python新手,最近开始了这个项目。我觉得我很接近,但我不知道为什么我的值在输入一组新的数字时不会更新?我认为这是最后一个函数中的一个问题。图片描述:


def cow_bull():
游戏=真实
idx=0
cow=0#在错误的位置正确地猜到了麻木
bull=0#猜测正确,麻木在正确的位置
计数=1
尽管如此:
n=(玩家列表(“输入你的猜测:”)
当idx
嘿,你能给我们提供完整的代码吗?嗨,也许
idx
变量和其他变量需要在
while
循环中重置为
0
?而不是while循环,对范围内的idx使用
(len(n)):
数据类型相同吗
game\u list\u official
看起来像一个整数列表,这就是
player\u list()
返回的吗?它不允许我上传完整的代码列表,因为它太长了。我将尝试在这里发布一些建议//将while循环更改为for循环成功了!你能解释一下原因吗?//嘿,你能给我们提供完整的代码吗?嗨,也许
idx
变量和其他变量需要在
while
循环中重置为
0
?而不是while循环,对范围内的idx使用
(len(n)):
数据类型相同吗
game\u list\u official
看起来像一个整数列表,这就是
player\u list()
返回的吗?它不允许我上传完整的代码列表,因为它太长了。我将尝试在这里发布一些建议//将while循环更改为for循环成功了!你能解释一下原因吗//

def cow_bull():
    game=True
    idx=0
    cow=0       # Guessed a numb correctly in wrong place
    bull=0      #Guessed numb correctly in correct place
    count=1
    while True:
        n=(player_list("Enter your guess!: "))
        while idx < len(n):
            if n == game_list_official:
                print("You WIN!!!, It took you", count, "attempt!!!")
                break
            elif n[idx] == game_list_official[idx]:
                bull+=1                                                                               
            elif n[idx] in game_list_official and n[idx] != game_list_official[idx]:                      
                cow+=1
            idx+=1
            count+=1

        print("cow",cow,"bull",bull)

cow_bull()