Python Forum
Rock, paper, scissors spelling error
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rock, paper, scissors spelling error
#4
(Jan-19-2021, 08:52 AM)buran Wrote: validate the user input
Thank you! they both helped a lot.
I did this:
player1 = input("Give player 1 a name:\n")
player2 = input("Give player 2 a name:\n")

choices = ['rock', 'paper', 'scissors']
def move(player):
    while True:
        choice = input(f"{player}, choose one:(rock/paper/scissors) ")
        if choice in choices: return choice
        print("Check the spelling.")

wins = {'rock': 'scissors', 'paper': 'rock', 'scissors': 'paper' }
while True:
    choice1 = move(player1)
    choice2 = move(player2)
    print(f"{player2} wins!" if choice1 == wins[choice2] else f"{player1} wins!" if choice2 == wins[choice1] else "Same!")
    if input("Continue?(y/n) ") == 'n': break
Out of curiosity, now in the
def move(player):
I validate the input which is in the function itself.
But can I define a validation function that uses 'while True' to validate an input that is defined outside of it? Like calling a validate function on any output that is outside of the function?!
Something like this:
answer = input("some stuff here: ")

def validate(parameter):
    while True:
        if parameter is blah blah: break
        print("correct the answer.")
        #some code to return to the answer outside

#Now calling the validate function on answer
validate(answer)
Reply


Messages In This Thread
RE: Rock, paper, scissors spelling error - by buran - Jan-19-2021, 08:52 AM
RE: Rock, paper, scissors spelling error - by banidjamali - Jan-19-2021, 12:04 PM
RE: Rock, paper, scissors spelling error - by buran - Jan-19-2021, 01:17 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  I attempted to make a rock paper scissors bot for homework Intellectual11 3 3,022 Jun-24-2021, 08:00 PM
Last Post: deanhystad
  Rock, Paper, Scissors Game kramon19 2 5,487 Jan-10-2020, 08:18 AM
Last Post: perfringo
  I need help with a python Rock Paper Scissors game urgently. Riff_Raff 3 6,030 Dec-05-2018, 09:13 PM
Last Post: nilamo
  Rock, Paper, Scissors Advanced that saves, loads, and keeps statistics EvanCahill 0 5,318 Jul-21-2018, 07:32 PM
Last Post: EvanCahill
  Rock Paper Scissors Warmlawpk441 4 5,283 Oct-11-2017, 10:55 AM
Last Post: gruntfutuk
  Rock paper scissors game samiraheen 3 6,570 Oct-03-2017, 07:07 PM
Last Post: buran
  The Python Book altered rock paper scissors Python_Noob 0 3,025 Sep-18-2017, 06:13 AM
Last Post: Python_Noob
  HELP---problems with rock paper scissors games kalt91 2 4,277 Sep-15-2017, 04:51 PM
Last Post: micseydel
  Rock, Paper, Scissors game help.. hentera 3 5,194 May-19-2017, 10:56 PM
Last Post: ichabod801
  Rock Paper Scissors game codeobri 3 13,581 Apr-28-2017, 01:02 AM
Last Post: codeobri

Forum Jump:

User Panel Messages

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