Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: While loop unending

Tags:

python

I am trying to get a conditioned while with or statements for an assignment for a game programming class. I am trying to use a loop something like this. They are not exactly like this, but it is 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've checked that tempstr is set to B or b, and they still continue to ask for an input instead of just ending the program.

like image 668
megmaconqueror Avatar asked Jun 15 '26 06:06

megmaconqueror


1 Answers

Try

While True:
    tempstr = input("Type anything ")
    if tempstr.lower()  == 'b':
        break
like image 157
Himal Avatar answered Jun 16 '26 20:06

Himal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!