0

For Some reason the loop wont carry out the command of yes and instead it just keeps repeating at the incorrect part

i tried changing the while to an if and it didn't help, I'm not sure why it doesn't work

FA=input ('Are there assignments to grade? Yes/No:')#FA refers to whether or not there are assignments to grade
FA=FA.upper()

while FA not in ('Yes', 'No'):
   print ('Please enter a valid input: either Yes or No')
   FA=input('Are there any assingments to grade? Yes/No:')
   FA=FA.upper()


#outputs
while FA == 'Yes':
  • 1
    I think you mean `FA.title()`. `.upper()` changes all characters in the string to upper case (so you would need to compare with `("YES", "NO")`. – Michael Delgado Nov 10 '22 at 01:50
  • 1
    Does this answer your question? [How can I capitalize the first letter of each word in a string?](https://stackoverflow.com/questions/1549641/how-can-i-capitalize-the-first-letter-of-each-word-in-a-string) – Michael Delgado Nov 10 '22 at 01:52

1 Answers1

0

The loop is getting stuck because of FA=FA.upper(). Because for example if the user inputs Yes the string gets converted to uppercase i.e. YES which is interpreted differently from Yes.

If you are converting the input string to uppercase then you'll have to use uppercase strings to check for correct input.

Below is the correct way to check for input.

while FA not in ('YES', 'NO'): // Use uppercase strings to check if input was valid
   print ('Please enter a valid input: either Yes or No')
   FA=input('Are there any assingments to grade? Yes/No:')
   FA=FA.upper() // Changes all letters to uppercase