如何减少我的代码冗余?

cho*_*on4 0 python

我想让这个程序减少更少,但我无法弄清楚如何.一方面,这个过程有一个模式,我觉得有一个更好的方法,而不是手动说明每一个可能的结果.另一方面,每种情况在其自身方面都是独一无二的.有关如何简化此代码的任何想法?

def calculate_Winner(user, npc):


    if user == 0 and npc == 0:
        return "The computer is scissor. You are scissor too. It is a draw."
    elif user == 0 and npc == 1:
        return "The computer is rock. You are scissor. You lose"
    elif user == 0 and npc == 2:
        return "The computer is paper. You are scissor. You win (;"


    elif user == 1 and npc == 0:
        return "The computer is scissor. You are rock. You win"
    elif user == 1 and npc == 1:
        return "The computer is rock. You are rock. It is a draw."
    elif user == 1 and npc == 2:
        return "The computer is paper. You are rock. You lose."


    elif user == 2 and npc == 0:
        return "The computer is scissor. You are paper. You lose"
    elif user == 2 and npc == 1:
        return "The computer is rock. You are paper. You win"
    elif user == 2 and npc == 2:
        return "The computer is paper. You are paper too. Draw"
Run Code Online (Sandbox Code Playgroud)

use*_*ica 5

move_names = ['scissor', 'rock', 'paper']
winner_strings = ["It's a draw.", "You win.", "You lose."]

def get_result_string(player_move, computer_move):
    winner = player_move - computer_move % 3
    return 'You played {}. The computer played {}. {}'.format(
            move_names[player_move],
            move_names[computer_move],
            winner_strings[winner])
Run Code Online (Sandbox Code Playgroud)