i m new to all of the programming and i mlearning python right now.
i m learning right now loops for/while.
i need to write a word guessing game. i think i have figured out the morst but i m stucked with one thing
when someone tips a word and it has the same letters as the hidden word it should show the letters in .lower() but if the letter is also in the right spot i should print it .upper().
example
hidden word flower
guess glhtwu
print _ L _ _w_
i hope this is better. i chanceled the random out so that the testing is faster.
i have everthing else i only need to fix that.
thx for your help
i m learning right now loops for/while.
i need to write a word guessing game. i think i have figured out the morst but i m stucked with one thing
when someone tips a word and it has the same letters as the hidden word it should show the letters in .lower() but if the letter is also in the right spot i should print it .upper().
example
hidden word flower
guess glhtwu
print _ L _ _w_
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
#import random #random_words = ('flower','house','python','mother','church','monster') hidden_word = 'flower' #random.choice(random_words) guess = '' guess_count = 0 hint = '_' * len (hidden_word) print ( 'Welcome to the word guessing game!' ) print () while guess ! = hidden_word: print ( f 'Your hint is: {hint}' ) guess = input ( 'What is your guess? ' ).lower() # counts the guesses guess_count = guess_count + 1 # this controls the lenghs of the guess if len (guess) > len (hidden_word): print ( 'Sorry, the guess must have the same number of letters as the secret word.' ) elif len (guess) < len (hidden_word): print ( 'Sorry, the guess must have the same number of letters as the secret word.' ) #this one one the bottom was a try but doesn t work for char in guess: if char.lower() = = hidden_word.lower(): print (char.upper() , end = '')[ / color] else : print ( 'Congratulation! you guess it! ' ) print ( f 'It took you {guess_count} guesses. ' ) print () |
i have everthing else i only need to fix that.
thx for your help
buran write Oct-07-2024, 11:18 AM:
Please, post your code inline, using BBcode tags, not as attachment
Please, post your code inline, using BBcode tags, not as attachment