Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.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 从单词列表中逐字打印 随机导入 列表1=[“芯片”] random\u word=random.choice(列表1) 用户猜测=0 猜测极限=10 索引=0 索引\u 1=随机词[索引] 当用户猜测时,我相信您希望在循环的每个迭代中重新请求用户输入,因此_Python_Python 3.x - Fatal编程技术网

Python 从单词列表中逐字打印 随机导入 列表1=[“芯片”] random\u word=random.choice(列表1) 用户猜测=0 猜测极限=10 索引=0 索引\u 1=随机词[索引] 当用户猜测时,我相信您希望在循环的每个迭代中重新请求用户输入,因此

Python 从单词列表中逐字打印 随机导入 列表1=[“芯片”] random\u word=random.choice(列表1) 用户猜测=0 猜测极限=10 索引=0 索引\u 1=随机词[索引] 当用户猜测时,我相信您希望在循环的每个迭代中重新请求用户输入,因此,python,python-3.x,Python,Python 3.x,从单词列表中逐字打印 随机导入 列表1=[“芯片”] random\u word=random.choice(列表1) 用户猜测=0 猜测极限=10 索引=0 索引\u 1=随机词[索引] 当用户猜测时,我相信您希望在循环的每个迭代中重新请求用户输入,因此将user\u guess=input(“输入您的猜测”)移动到while循环中 import random list1 = ["chips"] random_word = random.choice(list1) use

从单词列表中逐字打印
随机导入
列表1=[“芯片”]
random\u word=random.choice(列表1)
用户猜测=0
猜测极限=10
索引=0
索引\u 1=随机词[索引]

当用户猜测时,我相信您希望在循环的每个迭代中重新请求用户输入,因此将
user\u guess=input(“输入您的猜测”)
移动到
while
循环中

import random

list1 = ["chips"]
random_word = random.choice(list1)
user_guesses = 0
guess_limit = 10
index = 0
index_1 = random_word[index]

while user_guesses <= guess_limit:
    user_guess = input("enter your guess: ")   
    if index_1 == user_guess:
        print(index_1)
        index +=1
        user_guesses +=1
list1=[“芯片”]
random\u word=random.choice(列表1)
用户猜测=0
猜测极限=10
#(从此处删除)
索引=0
索引\u 1=随机词[索引]

当用户猜测时,我认为用户猜测应该在循环中每次都得到更新,对吗?还是你第一次输入了正确的值?是的,但问题是索引_1应该从“c”到“h”到“i”到“p”再到“s”,但现在它只停留在“c”是的,但问题是索引_1应该从“c”到“h”再到“i”再到“p”再到“s”,但现在它只停留在“c”您正在增加循环中的索引,但索引_1也应该用以下语句更新:index_1=random_word[index]在循环中谢谢@阿梅亚尔
list1 = ["chips"]
random_word = random.choice(list1)
user_guesses = 0
guess_limit = 10
# (removed from here)
index = 0
index_1 = random_word[index]

while user_guesses <= guess_limit:
    user_guess = input("enter your guess: ")    #<<<<<<<<<<<<<<<<<<<<<<<<<<
    if index_1 == user_guess:
        print(index_1)
        index +=1
        user_guesses +=1