0

I am trying to input a gender of either 'M' or 'F' into an array however when i try to check for the presence of either M or F the while loop checks the variable for presence of M and F instead of either of them.

Count1 = 0
Count2 = 0
VarArray = []
while Count1 < 1:
    VarArray.append(str(input('Enter your name: ')))
    Count2 = Count2 + 1
    VarArray.append(str(input('Enter your gender as M or F: ')))
    while VarArray[Count2] != 'M' or VarArray[Count2] != 'F':
        VarArray.append(str(input('Please enter your gender as either \'M\' or \'F\': ')))
    VarArray.append(int(input('Enter your score for test 1: ')))
    VarArray.append(int(input('Enter your score for test 2: ')))
    VarArray.append(str('|'))
    Count1 = Count1 + 1
    Count2 = Count2 + 1
print(VarArray)

Is there a way to get this to work using this method or do i need to create two separate while loops for this.

  • 1
    Common mistake. To test if `x` is neither `a` nor `b`, you need `x != a and x != b`. You have an or. – Frank Yellin Sep 11 '20 at 00:59
  • or to do away with the common mistake (which I often do ;P) you could ```while VarArray[Count2] not in ["M", "F"]:``` – ewokx Sep 11 '20 at 01:01

0 Answers0