0

This code should ask the user for an input and if they do not enter one of five strings then it should keep asking until they do. However when I added the while loop to accomplish this it does not recognize the valid inputs, it still keeps looping the input

def main():
    print('----- AVATAR -----')

    avatar = input('Select an Avatar or create your own:\n')
    #if input is not one of these V then it should keep asking
    #if input is one of these, go to if statements
    while (avatar != 'exit' or avatar != 'Jeff' or 'custom' or 'Chris' or 'Adam'):
        avatar = input('Select an Avatar or create your own:\n')

    if avatar == 'exit':
        return avatar
    elif avatar == 'Jeff':
        hat('both')
        face("True", "0")
        arm_style("=")
        torso_length(2)
        leg_length(2)
        shoe_style("#HHH#")
    elif avatar == 'Adam':
.....

And then there are elif statements for all 5 valid inputs

jodag
  • 19,885
  • 5
  • 47
  • 66
monica
  • 31
  • 4

2 Answers2

0

It might be because in your while clause you stop checking if 'avatar !=' and just have 'or 'custom'', and 'or 'Chris'' etc.

This is equivalent to saying 'or a string'. A non-empty string by itself in a boolean check evaluates to 'true'. So, your while loop has constant 'true' values due to you not checking the string equals something, just that a string is.

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
DMarczak
  • 729
  • 1
  • 9
  • 19
-1

The code for your loop is incorrect. It needs to be the following:

while (avatar != 'exit' and avatar != 'Jeff' and avatar !='custom' and avatar !='Chris' and avatar !='Adam'):
C. Fennell
  • 992
  • 12
  • 20