You are converting the length of those two strings, to strings themselves - meaning the values of guess_1
and guess_2
will be the string "11". So, when you compare if phrase < guess_1:
, you're checking if the string phrase
is in a lower lexicographical order.
Here's how the code would look if it correctly checked against the length of the secret phrase:
secret = 'BRINGCOFFEE'
guess_1 = len(secret)
guess_2 = len(secret)
while(secret != True):
phrase = input('Guess the Secret phrase! \nGuess:')
if len(phrase) < guess_1:
print('Too Few Characters')
elif len(phrase) > guess_2:
print('Too Many Characters')
However it's not clear why you have the guess_1
and guess_2
variables. From what I can see you could just do the following to have a complete phrase-checking program:
secret = 'BRINGCOFFEE'
while True:
phrase = input('Guess the Secret phrase! \nGuess:').upper() # convert to uppercase since the secret is uppercase
if len(phrase) < len(secret):
print('Too Few Characters')
elif len(phrase) > len(secret):
print('Too Many Characters')
elif phrase == secret:
break
print('You guessed correctly!')
One more thing to point out is that there was no case for handling a guess with a correct length. You could add in this condition like so:
elif len(phrase) == len(secret):
print("Same Number of Characters, Wrong Phrase")