Как вернуть входное значение? [дубликат]Python

Программы на Python
Anonymous
Как вернуть входное значение? [дубликат]

Сообщение Anonymous »

Я пытаюсь вернуть переменную «user_input» в цикле while в функции «make_user_choice». Я не знаю, как мне поступить.
Вот мой код:
import random
"""Supports a round of rock, paper, scissors between a user and a computer."""

user_input = input("Choose one: rock, paper, scissors? ")

def make_user_choice():
"""Returns the user's choice of rock, paper, or scissors if it is correct."""
while user_input != "rock" or user_input != "paper" or user_input != "scissors":
print("that is not a valid imput. please try again")
break
return user_input
return user_input

def make_computer_choice():
"""Returns the computer's random choice of rock, paper, or scissors."""
choice = random.randint(1,3)
if choice == 1:
return "rock"
elif choice == 2:
return "paper"
if choice == 3:
return "scissors"

def wins_matchup(choice, opponent_choice):
"""Returns True if the first player's choice wins over their opponent.
Choices can be rock, paper, or scissors. Assumes the choices are different.
"""
return choice == "rock"

def format_score(user_score, computer_score):
"""Returns a formatted version of the players's current scores."""
return ">> Score: " + str(user_score) + "-" + str(computer_score)

и вот результат:
Choose one: rock, paper, scissors? rtgyhuji
that is not a valid imput. please try again
rtgyhuji (you) vs. rock
Computer wins!
>> Score: 0-1
that is not a valid imput. please try again
rtgyhuji (you) vs. paper
Computer wins!
>> Score: 0-2

Вернуться в «Python»