Anonymous asked in Computers & InternetProgramming & Design · 9 months ago

Python homework help?

This is part two of four. I have a program that stores a secret word and reports whether or not a user’s guess is in the word. The program should print a string with dashes and letters in the correct places based on the user’s guesses, like this: Guess: e

That letter is in the word!


My code does this:


Guess: a

That letter is in the secret word!

Guess: e

That is not in the secret word

I have to make a string variable called dashes that holds a number of dashes equal to the length of the secret word. If the secret word was “eggplant”, the dashes variable would have eight dashes. I then have to 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.

I don't know how to create the update_dashes so that it will update the dashes. I will try to include my current code in the answers.   

2 Answers

  • EddieJ
    Lv 7
    9 months ago
    Favorite Answer

    I've been looking for an answer with your code.  Unfortunately, Y!A sometime doesn't display an answer if it doesn't like something about it.  I don't know if you tried to post your code.

  • Anonymous
    9 months ago

    the basic format is   

    def <name>(variables to pass):  return <something>

    and then set your function equal to something like:<varToOutput> = update_dashes(secretWord,currentState,recentGuess)

    The above is the call and the assignment in one step. As an example, the following would print "test"def functionName(var1, var2, var3):

      return var1 + var2 + var3

    print(functionName("te", "s", "t"))

    Provided you're not looking for the answer but instead want to learn it on your own, the above should get you where you need to go.

    Picture attached in case pseudocode is dropped

    Attachment image
Still have questions? Get your answers by asking now.