Reputation: 33
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.
Upvotes: 3
Views: 458
Reputation: 31
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
Upvotes: 0
Reputation: 1371
Try
While True:
tempstr = input("Type anything ")
if tempstr.lower() == 'b':
break
Upvotes: 3