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.
2 Answers 2
Try
While True:
tempstr = input("Type anything ")
if tempstr.lower() == 'b':
break
3 Comments
while True wrapper and break out of it when we already know the condition that should trigger the while to break?From your question, i have understood that you want to get out of the program whenever B letter is typed and we can make it possible bye just using simple if statement.
Try this,
while True:
tempstr = input("Type B ")
if tempstr == "B" or tempstr == "b":
break
Type B d
Type B e
Type B g
Type B b