Python: while the loop is infinite

I am trying to get a conditional expression with instructions or instructions for an assignment for a game programming class. I am trying to use a loop like this. They are not quite the same, but they are the same conditions for the while statement.

tempstr = input("Type B ")
while tempstr != "B" or tempstr != "b":
     tempstr = input("Type anything ")

      

I have also tried.

tempstr = input("Type B ")
while tempstr == "B" or tempstr == "b":
     tempstr = input("Type anything ")

      

As well as.

 while tempstr == "B" or tempstr == "b":
      tempstr = input("Type anything ")

      

I have verified that tempstr is set to B or b and they still keep asking for input and not just ending the program.

+3


source to share


1 answer


Try



While True:
    tempstr = input("Type anything ")
    if tempstr.lower()  == 'b':
        break

      

+3


source







All Articles