2023-05-20

While loop -- Count of len(Words) loops six time of the "flower" has six Letter

While count<len(word) loops six times because the word "Flower" has six letters. i then need to ask the user to guess again, and if the guess is incorrect , run that same loop again, and then ask for input again until the input is finally correct. how can i accomplish this? again, my goal: Run loop six time ask for input. incorrect input restarts process...

word = 'flower'
print()
print('Hint : ')
count = 0
while count< len(word):
    print('_', end='')
    count += 1
print()
print()
attempts = 0 
guess = input(' what is your guess? ')
count=0
while len (guess) != len(word):
    guess = input('Please enter correct length of word : ')
    attempts += 1

while count < len(guess):
    if guess [count].lower() not in word:
        print('_', end='')
    elif guess [count].lower() == word[count]:
        print(guess[count].upper(),end='')
    else:
        print(guess[count].lower(),end='')
        count += 1
attempts += 1
print()
print(f'it took you {attempts} guesses.')
print()


No comments:

Post a Comment