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
#4
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? Why do I have to resort to creating a list and executing the while statement or even the for statement from a list?

(Mar-18-2021, 02:26 PM)BashBedlam Wrote: I would make a separate function to keep looping until it got a valid input and then return that string, like this:

def get_valid_input (player) :
	acceptable_answers = ('rock', 'paper', 'scissors')
	prompt = ", you are up, what's it going to be, rock, paper or scissors? "
	answer = 'BashBedlam was here.'
	while answer not in acceptable_answers :
		answer = input ('\n' + player +  prompt)
		answer = answer.lower ()
	return answer

def start():
	player1 = input("Player one, What is your name? ")
	player2 = input("Player two, What is your name? ")
	user1 = get_valid_input (player1)
	user2 = get_valid_input (player2)
	return (player1, user1, player2, user2)

print (start ())
Reply


Messages In This Thread
RE: Problem restricting user input in my rock paper scissors game - by ashergreen - Mar-19-2021, 10:58 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Rock Paper Scissors Project in Python ankitdixit 8 4,918 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 951 Apr-08-2023, 05:40 PM
Last Post: MCL169
  user input values into list of lists tauros73 3 1,102 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,137 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,977 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