Jafele
Jafele
Guessing game codehs answers. Number guessing game code. 5.8.2 guessing game codehs answers. Guess the passcode codehs answers. 6.1.1 guessing game codehs answers.
Scan this QR code to download the app now Or check it out in the app stores Scan this QR code to download the app now Or check it out in the app stores Scan this QR code to download the app now Or check it out in the app stores Scan this QR code to download the app now Or check it out in the app stores Download the Expo app, then: Android:
Scan this QR code from the Expo app. iPhone: Scan this QR code from your camera app. Don't have Expo yet?
I am currently stuck on exercise 10.1.3 on CodeHS, which is essentially a part in making a hangman game, without the hangman.
I have my code nearly complete for this section of the game, yet for some reason whenever new input is given (for a letter), it clears previous input. obstetrics by ten teachers 20th edition pdf Here is my code: secret_word = "character" dashes = "-" * len(secret_word) print(dashes) #Prints the first row of dashes to indicate word length def
get_guess(): while True: guess = input("Guess: ") if isinstance(guess, int): print("Your guess must be a lowercase letter.") else: if guess.islower(): if len(guess) == 1: return guess else: print("Your guess must have exactly one character.") def update_dashes(secret_word, dashes, guess): result = "" for i in range(len(secret_word)): if secret_word[i] ==
guess: result = result[:i] + guess + result[i + 1:] else: result = result + "-" return result while True: guess = get_guess() if guess in secret_word: print("The letter is in the word.") else: print("That letter is not in the word.") print(update_dashes(secret_word, dashes, guess)) #We believe the issue is here, it is printing the full set each time this loops.
When run, this is the output: --------- Guess: c The letter is in the word. rbse physics book class 12 pdf
c----c--- Guess: h The letter is in the word. -h------- Guess: The code should be adding the "h" to the word, yet it is 'overwriting' what is already there. 40438114052.pdf
This is what I want it to print: --------- Guess: c The letter is in the word. c----c--- Guess: h The letter is in the word. ch---c--- Guess: Note that the word that should be guessed is "character". And finally, this is the part of the assignment that relates to what the current problem is: Step 2 - Update the Dashes Here’s the tricky part. Write a function called
update_dashes that takes three string arguments - the secret word, the current state of dashes, and the most recent guess - and returns the new state of dashes. So, for example, if the word is "eggplant", the current value of dashes is "e-------", and the guess is "g", the function should return "egg-----". If the word is "eggplant", the current value of
dashes is "e-------", and the guess is "z", the function should return "e-------" (nothing changes, since the guess was incorrect). 2011 srx owners manual Here’s how you might go about this. In your function, start with an empty result string. Write a for loop from 0 up to but not including the length of your secret word. Say you use the variable i in your
for loop. Compare the character in secret_word at index i to the guess. If they’re equal, then that means the guess matches that letter in the word, so you should add the guess to the result.
Otherwise, the guess does not match that letter in the word, so you should add whatever was at index i in dashes to your result.
Wait, why don’t I just add a dash in the second case? If you just add a dash whenever the guess doesn’t match the character in secret_word at index i, that will wipe out any correct guesses the user has already made! Imagine the case where the word is “eggplant”, the state of dashes is “e——-“, and the guess is “g”. If you always add a dash when the
guess doesn’t match the character in secret_word at index i, the result would be “-gg—–”. Suddenly, the “e” is gone, because “g” did not match “e”! By instead using dashes at index i, you might append either a letter or a dash, depending on whether or not the user had already guessed that letter prior to the current guess.
Once your for loop is done, your result string should have letters and dashes in all the right places, so you can just return it! You are welcome for the free answers click on the get answers now button if you need any help please use the contact button, This is followed by codehs teachers even if on incongnito vacation rental lease agreement pdf