Python RPSSL игра от The Big Bang Theory, что делать, если вход! = Варианты, перечисленные - PullRequest
0 голосов
/ 05 октября 2018

это заняло у меня некоторое время, но я создал игру «Рок, бумага, ножницы, спок, ящерица» из теории большого взрыва, теперь я не знаю, сделан ли мой код наиболее эффективным способом, и мне сказалиЯ мог бы использовать цикл do while, чтобы сделать это проще, но это не связано с моим вопросом.Мой вопрос: когда кто-то вводит данные, которые они могут вводить, все, что они хотят, это не обязательно должен быть «камень», «бумага», «ножницы», «спок», «ящерица».Есть ли способ заставить их ввести любой RPSSL, есть ли способ заставить пользователя выбрать один из следующих вариантов.Я понимаю, что каждый вопрос "Есть ли способ", как правило, да, есть способ, но я искал немного о том, как сделать это в первую очередь на YouTube, но немного на этом сайте, но я могу найти способ сделать это, как яЯ слышал, как иногда сложно работать с входными данными, и что-то с более новым обновлением Python изменило то, как мы используем входные данные.Заранее спасибо, и я ценю ваше время.

#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")

1 Ответ

0 голосов
/ 05 октября 2018

Вы можете сделать это с помощью цикла while с вводом данных от игрока:

#Main
import random
computer_rps = ['ROCK','PAPER','SCISSORS','SPOCK','LIZARD']
valid_input = False  # Make sure to enter at least once
while valid_input is False:
    player_rps = input('Rock, Paper, Scissors, Lizard, or Spock:\t').upper()
    if player_rps in computer_rps:
        valid_input = True

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!")

Это продолжается до тех пор, пока вы не получите действительный ввод.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...