-2

I'm here for my young son. I need your help.

How do you 1) make a right answer to any one of several answers. And how do you 2) create several input prompts that will display if an answer is wrong. For example, the program is supposed to let a user guess the secret_word = "love". (The prompt says "it's what the world needs now". If you know the song, the lyric then goes "love sweet love".)

Anyway, the user might type in "Love" or "LOVE" or "Love sweet love" or "LOVE SWEET LOVE" or whatever. I'm willing to accept those and many other answers as correct. How do I program that? See my code below.

The second problem is linked to this. Should they get a wrong answer, like "politicians", my while loop gives them 2 more tries. Each try I want a DIFFERENT prompt, such as "Oops. Not quite, give it one more try" or "Here's a clue, it begins with L". How do I code that. Anyway, thanks again. Here's that code. Tell me what you think:

secret_word = "love" 

# I want these options too: "LOVE", " Love", "love sweet love",

guess=""

guess_count = 0

guess_limit = 3

out_of_guesses = False



while guess != secret_word and not(out_of_guesses):

if guess_count < guess_limit:

guess = input("Guess the guess-word. 3 tries. (It's 'what the world needs now'): ")

guess_count += 1

else:
    out_of_guesses = True

if out_of_guesses:
    print("Out of Guesses! You lose! The answer was " + secret_word + "!")

else:
    print("You're right! You win! It IS " + secret_word + "! Fantastic job.")
vash_the_stampede
  • 4,590
  • 1
  • 8
  • 20
Jon C
  • 1
  • 1
  • 1
    Welcome to StackOverflow. Please read and follow the posting guidelines in the help documentation, as suggested when you created this account. [On topic](http://stackoverflow.com/help/on-topic), [how to ask](http://stackoverflow.com/help/how-to-ask), and [... the perfect question](https://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/) apply here. StackOverflow is not a design, coding, research, or tutorial resource. – Prune Oct 09 '18 at 00:03
  • Please review your question and edit it. Indentation in Python is critical and I doubt this code will work if I copy-paste it on my system. Ex. the `while` and the `if` are on the same indentation. – Nic3500 Oct 09 '18 at 04:41

1 Answers1

0

By using .lower() for comparing our guess to secret_word we can handle the case possibilities of love. We can turn secret_word into a list that contains love sweet love to handle the other possibility.

Next we can restructure our while loop so the condition is while guess.lower() not in secret_word and guess_count <3. This will eliminate the need for guess_limit and out_of_guesses.

Once the loop has exited we can then use our if/else with guess.lower()

secret_word = ["love", 'love sweet love']

guess=""
guess_count = 0
out_of_guesses = False


while guess.lower() not in secret_word and guess_count < 3:
    guess = input("Guess the guess-word. 3 tries. (It's 'what the world needs now'): ")
    guess_count += 1


if guess not in secret_word:
    print("Out of Guesses! You lose! The answers was: {}!".format(secret_word[0]))
else:
    print("You're right! You win! It IS " + secret_word[0] + "! Fantastic job.")
vash_the_stampede
  • 4,590
  • 1
  • 8
  • 20
  • Thanks that's great. , and everything is working except specifically when I try "Love" or "Love sweet love" the program goes straight to "Out of guesses. So I just added "Love" and "Love Sweet Love" to the secrets_words list. Anyway, thanks soo much. Here's what I got. Put it in your IDE and see what you get. Make sure to test all the possible version and suggest improvements. – Jon C Oct 10 '18 at 02:02
  • Hey no prob, @JonC glad it helped and hmm good thing you figured that little error out :) if this solved your problem appreciate if you accepted answer, cheers! – vash_the_stampede Oct 10 '18 at 02:03
  • secret_words = ["love", "Love", 'Love Sweet Love', 'love sweet love'] guess="" guess_count = 0 while guess.lower() not in secret_words and guess_count < 3: guess = input("Guess the guess-word. 3 tries. (It's 'what the world needs now'): ") guess_count += 1 if guess not in secret_words: print("Out of Guesses! You lose! The answer was: " + secret_words[0] + "!") else: print("You're right! You win! It IS " + secret_words[0] + "! Fantastic job.") – Jon C Oct 10 '18 at 02:36