user13999461
user13999461

Reputation:

Print letter by letter from a words-list

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

My question is that why doesn't the variable index_1 move forward from "c" to "h" as it should because the word is chips. index_1 stays only at "c".

Upvotes: 1

Views: 136

Answers (1)

Red Twoon
Red Twoon

Reputation: 755

I believe you want to re-ask for user input every iteration of the loop, so move user_guess = input("enter your guess: ") into the while loop

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

Upvotes: 2

Related Questions