Python中石头剪刀布游戏的问题

sdnqo3pr  于 2022-12-27  发布在  Python
关注(0)|答案(1)|浏览(165)

这是我的第一天对编码和开始对岩石剪刀布游戏,我得到这个错误我怎么能修复这个
输入:

import random

def get_choices():
    player_choice = (input('Enter a choice (Rock , Paper , Scissors)'))
    c_choices = ['Rock', 'Paper', 'Scissors']
    computer_choice = random.choice(c_choices)
    choices = {'player': player_choice, 'computer': computer_choice}
    return choices

def check_win(player,computer):
    print(f"You chose {player},computer chose {computer}")
    if player == computer:
        return "its a tie!"
    elif player== 'rock':
        if computer=='scissors':
            return "ROCK SMASHES SCISSORS!, YOU WIN!"
        else:
            return "PAPER COVERS ROCK!, YOU LOSE!"

    elif player== 'paper':
        if computer=='rock':
            return "PAPER COVERS ROCK, YOU WIN!"
        else:
            return "SCISSOR CUTS PAPER!, YOU LOSE!"

    elif player == 'scissors':
        if computer == 'paper':
            return "SCISSORS CUTS PAPER!, YOU WIN!"
        else:
            return "ROCK SMASHES SCISSORS!, YOU LOSE!"

choices = get_choices()
result = check_win(choices['player'], choices['computer'])
print(result)

输出
It should have been a tie as directed on line 13/14
我期待平局

pxiryf3j

pxiryf3j1#

c_choices中的字符串大写。
def check_win()中,你将它们与小写字符串进行比较。
use:

c_choices = ['rock', 'paper', 'scissors']

而不是:

c_choices = ['Rock', 'Paper', 'Scissors']

相关问题