mus0082
Badges: 2
Rep:
?
#1
Report Thread starter 1 month ago
#1
while guess != secret_word and not (out_of_guesses):
if counter < limit:
guess = input("Enter an alphabeth 1: ")
counter += 1
print("Again")
else:
out_of_guesses = True

if out_of_guesses:
print("out of guesses")
else:
print("you got it")i m trying to solve one problem but i cant i need help and the problem is when ever i guess the correct word this program printing again and you got it it should not print again when i guessed the correct word. can someone help me?secret_word = "D"
secret_word1 = "w"
secret_word2 = "a"
secret_word3 = "r"
secret_word4 = "f"
secret_word_Whole = "Dwarf"these are the variables.
0
reply
winterscoming
Badges: 19
Rep:
?
#2
Report 1 month ago
#2
(Original post by mus0082)
Code:
while guess != secret_word and not (out_of_guesses):
    if counter < limit:
        guess = input("Enter an alphabeth 1: ")
        counter += 1
        print("Again")
    else:
        out_of_guesses = True

if out_of_guesses:
    print("out of guesses")
else:
    print("you got it")
i m trying to solve one problem but i cant i need help and the problem is when ever i guess the correct word this program printing again and you got it it should not print again when i guessed the correct word. can someone help me?
Code:
secret_word = "D"
secret_word1 = "w"
secret_word2 = "a"
secret_word3 = "r"
secret_word4 = "f"
secret_word_Whole = "Dwarf"
these are the variables.
Have a look at the logic here:
Code:
while guess != secret_word and not (out_of_guesses):
    if counter < limit:
        guess = input("Enter an alphabeth 1: ")
        counter += 1
        print("Again")

    else:
        out_of_guesses = True
To figure out why it's doing that, look at what this means in plain English:
Code:
Keep on repeating as long as: guess is not the secret word AND out_of_guesses is false:

    If the counter is less than the limit (there are guesses remaining)

        Ask the user
        Add 1 to the counter
        print "Again" to the console

    End If

End Repeat
Consider what's happening step-by-step -- the word "Again" will always be displayed on the screen after the program has asked the user to enter a guess.
(Except for the first time, because that happens outside of the loop).

Consider the line where you're printing the word 'Again' -- What if you change the order of the instructions so that print("Again") happens on the line before the program asks the user, instead of printing it afterwards?
Last edited by winterscoming; 1 month ago
0
reply
mus0082
Badges: 2
Rep:
?
#3
Report Thread starter 4 weeks ago
#3
I dont want
0
reply
X

Quick Reply

Attached files
Write a reply...
Reply
new posts
Back
to top
Latest
My Feed

See more of what you like on
The Student Room

You can personalise what you see on TSR. Tell us a little about yourself to get started.

Personalise

University open days

  • University of Hertfordshire
    All Subjects Undergraduate
    Sat, 22 Feb '20
  • Ravensbourne University London
    Undergraduate Open Day Undergraduate
    Sat, 22 Feb '20
  • Sheffield Hallam University
    Get into Teaching in South Yorkshire Undergraduate
    Wed, 26 Feb '20

People at uni: do initiations (like heavy drinking) put you off joining sports societies?

Yes (412)
67.21%
No (201)
32.79%

Watched Threads

View All