Reputation: 1
print("\t \t \t What's the password?")
print("\t you have 5 chances to get it right! \n")
secret_word = "green"
guess = ""
guess_count = 0
guess_limit = 5
out_of_guesses = False
hintA = "Ashtons' favorite color"
print("Here is a hint: "+ hintA)
#while loop
while guess != secret_word and not (out_of_guesses):
if guess_count < guess_limit:
guess = input("Enter guess: ")
guess_count += 1
#elif guess_count == 2:
#print("Here is a hint: "+ hintA)
else:
out_of_guesses = True
if out_of_guesses:
print("You have been locked out!")
else:
print("Correct password!")
I don't how to add a hint after like 2 or 3 guesses because without it would be impossible to do. Also the stuff in #
was my attempt
Upvotes: 0
Views: 64
Reputation: 7627
secret_word, guess_limit, hintA = "green", 5, "Here is a hint: Ashtons' favorite color"
print("\t\t\tWhat's the password?\n\tyou have " + str(guess_limit) + " chances to get it right!\n")
for i in range(guess_limit):
if i > guess_limit // 2: # more than half of the attempts are exhausted
print(hintA)
if input("Enter guess: ") == secret_word:
print("Correct password!")
break
else:
print("You have been locked out!")
Upvotes: 0
Reputation: 3780
you can try something like this :
print("\t \t \t What's the password?")
print("\t you have 5 chances to get it right! \n")
secret_word = "green"
guess = ""
guess_count = 0
guess_limit = 5
out_of_guesses = False
hintA = "Ashtons' favorite color"
#while loop
while guess != secret_word and not (out_of_guesses):
if guess_count < guess_limit:
if guess_count == 2:
print("Here is a hint: "+ hintA)
guess = input("Enter guess: ")
guess_count += 1
#elif guess_count == 2:
#print("Here is a hint: "+ hintA)
else:
out_of_guesses = True
if out_of_guesses:
print("You have been locked out!")
else:
print("Correct password!")
Upvotes: 1
Reputation:
Move your input outside the if...else
statements and change the position of the if...else
statements.
print("\t \t \t What's the password?")
print("\t you have 5 chances to get it right! \n")
secret_word = "green"
guess = ""
guess_count = 0
guess_limit = 5
out_of_guesses = False
hintA = "Ashtons' favorite color"
#while loop
while guess != secret_word and not (out_of_guesses):
guess = input("Enter guess: ")
if guess_count == 2:
print("Here is a hint: "+ hintA)
guess_count+=1
elif guess_count != guess_limit:
guess_count += 1
else:
out_of_guesses = True
if out_of_guesses:
print("You have been locked out!")
else:
print("Correct password!")
Output:
What's the password?
you have 5 chances to get it right!
Enter guess: red
Enter guess: blue
Enter guess: yellow
Here is a hint: Ashtons' favorite color
Enter guess: purple
Enter guess: beige
Enter guess: light green
You have been locked out!
Upvotes: 0