Python Forum
Problem restricting user input in my rock paper scissors game
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem restricting user input in my rock paper scissors game
#7
This is an incorrect conclusion.
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]
Reply


Messages In This Thread
RE: Problem restricting user input in my rock paper scissors game - by deanhystad - Mar-25-2021, 03:54 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Rock Paper Scissors Project in Python ankitdixit 8 4,917 Feb-23-2024, 03:14 PM
Last Post: DPaul
  problem in using input command akbarza 4 1,202 Oct-19-2023, 03:27 PM
Last Post: popejose
  problem in entering address of a file in input akbarza 0 677 Oct-18-2023, 08:16 AM
Last Post: akbarza
  WHILE LOOP NOT RETURNING USER INPUT AFTER ZerroDivisionError! HELP! ayodele_martins1 7 1,107 Oct-01-2023, 07:36 PM
Last Post: ayodele_martins1
  restrict user input to numerical values MCL169 2 950 Apr-08-2023, 05:40 PM
Last Post: MCL169
  user input values into list of lists tauros73 3 1,101 Dec-29-2022, 05:54 PM
Last Post: deanhystad
Information How to take url in telegram bot user input and put it as an argument in a function? askfriends 0 1,137 Dec-25-2022, 03:00 PM
Last Post: askfriends
Question Take user input and split files using 7z in python askfriends 2 1,136 Dec-11-2022, 07:39 PM
Last Post: snippsat
  Trying to create a visual rock paper scissors game urmom33 1 1,056 Dec-03-2022, 09:12 PM
Last Post: deanhystad
Sad how to validate user input from database johnconar 3 1,975 Sep-11-2022, 12:36 PM
Last Post: ndc85430

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020