Mar-25-2021, 03:54 AM
(This post was last modified: Mar-25-2021, 03:54 AM by deanhystad.)
This is an incorrect conclusion.
Here is input verification using "and"
Quote:I tried the OR instead of AND and it didn't work. It appears that doing the list/tuple thing seems to be the only way to get it to work.That you did not get it to work is no proof that any logical statement has to be written using "in". It is usually shorter, and in my opinion clearer, but an expression using "in" can be written using multiple comparisons strung together with "and" or "or", and maybe some parenthesis. I think your failing may be that you think C and Python logical expressions work the same way. If you don't really understand how "and" and "or" work in Python it is easy to get confusing results. Logically consistent, but not obvious to the new Python programmer.
Here is input verification using "and"
def player_input(player): inp = input(player + ' enter Rock, Paper or Scissor ').lower() while inp != "rock" and inp != "paper" and inp != "scissor": inp = input("Please enter Rock, Paper or Scissor ").lower() return inp names = [input('Name for player 1 '), input('Name for player 2 ')] plays = [player_input(name) for name in names]