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
#5
(Mar-19-2021, 10:58 AM)ashergreen Wrote: It works! But I have one question: When I programmed in C many years ago, the "user1 != "rock"...." line worked perfectly and also worked when I played with BASIC back in the day. Why doesn't it work with Python?

You have an issue with your logic, not your Python code. This line will always evaluate to True, unless user1 is somehow simultaneously equal to all three values at once (not possible):
user1 != "rock" or user1 != "paper" or user1 != "scissors"
You could use and instead of or to fix this, or you could use in to evaluate the variable against a group of options (a tuple in this case):
user1 not in ("rock", "paper", "scissors")
Reply


Messages In This Thread
RE: Problem restricting user input in my rock paper scissors game - by GOTO10 - Mar-19-2021, 11:14 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Rock Paper Scissors Project in Python ankitdixit 8 4,855 Feb-23-2024, 03:14 PM
Last Post: DPaul
  problem in using input command akbarza 4 1,143 Oct-19-2023, 03:27 PM
Last Post: popejose
  problem in entering address of a file in input akbarza 0 655 Oct-18-2023, 08:16 AM
Last Post: akbarza
  WHILE LOOP NOT RETURNING USER INPUT AFTER ZerroDivisionError! HELP! ayodele_martins1 7 1,072 Oct-01-2023, 07:36 PM
Last Post: ayodele_martins1
  restrict user input to numerical values MCL169 2 918 Apr-08-2023, 05:40 PM
Last Post: MCL169
  user input values into list of lists tauros73 3 1,075 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,100 Dec-25-2022, 03:00 PM
Last Post: askfriends
Question Take user input and split files using 7z in python askfriends 2 1,106 Dec-11-2022, 07:39 PM
Last Post: snippsat
  Trying to create a visual rock paper scissors game urmom33 1 1,040 Dec-03-2022, 09:12 PM
Last Post: deanhystad
Sad how to validate user input from database johnconar 3 1,930 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