vendredi 5 octobre 2018

Python RPSSL game from Big Bang Theory, what if the input != the choices listed

it took me some time but I created the Rock, Paper, Scissors, Spock, Lizard game from the Big Bang Theory, now I don't know if my code is made in the most efficient way and I've been told I could use a do while loop to make it easier but that does not involve my question. My question is when somebody enters an input they can enter whatever they want, it doesn't have to be "Rock" "Paper" "Scissors" "Spock" "Lizard". Is there a way where I can force them to enter either R.P.S.S.L, is there a way I can force the user to pick from the following options. I understand that every "Is there a way" question is usually yes there is a way but I've searched a bit about how to do this primarily on youtube but a little on this site but I can figure a way to do this as I've heard how Inputs are difficult at times and something with the newer python update changed how we use inputs. Thank you in advance and I appreciate your time.

#Main
import random
player_rps = input('Rock, Paper, Scissors, Lizard, or Spock:\t').upper()
computer_rps = ['ROCK','PAPER','SCISSORS','SPOCK','LIZARD']
game_rps = random.choice(computer_rps)
#Player
if player_rps == 'ROCK':
    print('Player picked Rock')
elif player_rps == 'PAPER':
    print('Player picked Paper')
elif player_rps == 'SCISSORS':
    print('Player picked Scissors')
elif player_rps == 'SPOCK':
    print('Player picked Spock')
elif player_rps == 'LIZARD':
    print('Player picked Lizard')
#Computer
if game_rps == 'ROCK':
    print('Computer picked Rock')
elif game_rps == 'PAPER':
    print('Computer picked Paper')
elif game_rps == 'SCISSORS':
    print('Computer picked Scissors')
elif game_rps == 'SPOCK':
    print('Computer picked Spock')
elif game_rps == 'LIZARD':
    print('Computer picked Lizard')
#Output for rock
if player_rps == "ROCK" and game_rps == "SCISSORS":
    print("Rock crushes scissors, the Player wins!")
if player_rps == "SCISSORS" and game_rps == "ROCK":
    print("Rock crushes scissors, the Computer wins!")
if player_rps == "ROCK" and game_rps == "PAPER":
    print("Paper covers rock, the Computer wins!")
if player_rps == "PAPER" and game_rps == "ROCK":
    print("Paper covers rock, the Player wins!")
if player_rps == "ROCK" and game_rps == "SPOCK":
    print("Spock vaporizes rock, the Computer wins!")
if player_rps == "SPOCK" and game_rps == "ROCK":
    print("Spock vaporizes rock, the Player wins!")
if player_rps == "ROCK" and game_rps == "LIZARD":
    print("Rock crushes lizard, the Player wins!")
if player_rps == "LIZARD" and game_rps == "ROCK":
    print("Rock crushes lizard, the Computer wins!")
#Output for paper
if player_rps == "PAPER" and game_rps == "LIZARD":
    print("Lizard eats paper, the Computer wins!")
if player_rps == "LIZARD" and game_rps == "PAPER":
    print("Lizard eats paper, the Player wins!")
if player_rps == "PAPER" and game_rps == "SCISSORS":
    print("Scissors cuts paper, the Computer wins!")
if player_rps == "SCISSORS" and game_rps == "PAPER":
    print("Scissors cuts paper, the Player wins!")
if player_rps == "PAPER" and game_rps == "SPOCK":
print("Paper disproves spock, the Player wins!")
if player_rps == "SPOCK" and game_rps == "PAPER":
    print("Paper disproves spock, the Computer wins!") 
#Output for scissors
if player_rps == "SCISSORS" and game_rps == "SPOCK":
    print("Spock smashes scissors, the Computer wins!")
if player_rps == "SPOCK" and game_rps == "SCISSORS":
    print("Spock smashes scissors, the Computer wins!")
if player_rps == "SCISSORS" and game_rps == "LIZARD":
    print("Scissors decapitates lizard, the Player wins!")
if player_rps == "LIZARD" and game_rps == "SCISSORS":
    print("Scissors decapitates lizard, the Computer wins!")
#Output for spock
if player_rps == "SPOCK" and game_rps == "LIZARD":
    print("Lizard poisons spock, the Computer wins!")
if player_rps == "LIZARD" and game_rps == "SPOCK":
    print("Lizard poisons spock, the Player wins!")
if player_rps == game_rps:
    print("It's a tie!")
else:
    print("Please enter the correct option: Rock, Paper, Scissors, Spock,             
    Lizard")

Aucun commentaire:

Enregistrer un commentaire