random.choice () выбирает более одного случайного значения - PullRequest
0 голосов
/ 05 июня 2019

Я работаю над созданием игры Rock Paper Scissors на python. И я хочу, чтобы система выбрала 1 случайное значение через раз. Но random.choice () выбирает 3 случайных значения за раз. Пожалуйста, помогите мне решить эту проблему.


    def random_computer_choice():
        """Choose randomly for computer."""

        # lookup random.choice()
        out = ['rock', 'paper', 'scissors']
        return random.choice(out)

    def rock():
        global human_choice, computer_choice
        global HUMAN_SCORE, COMPUTER_SCORE

        human_choice = 'rock'
        computer_choice = random_computer_choice()
        choice_result(human_choice, computer_choice)
    ```
    paper and scissors following the same format

    def choice_result(human_choice, computer_choice):

        global COMPUTER_SCORE
        global HUMAN_SCORE

        if human_choice == 'rock' and computer_choice == 'paper':
            COMPUTER_SCORE = COMPUTER_SCORE + 1
            print('Computer won')
        elif human_choice == 'rock' and computer_choice == 'scissors':
            HUMAN_SCORE = HUMAN_SCORE + 1
            print('You win')
        elif human_choice == 'paper' and computer_choice == 'rock':
            HUMAN_SCORE = HUMAN_SCORE + 1
            print('You win')
        elif human_choice == 'paper' and computer_choice == 'scissors':
            COMPUTER_SCORE = COMPUTER_SCORE + 1
            print('Computer won')
        elif human_choice == 'scissors' and computer_choice == 'rock':
            COMPUTER_SCORE = COMPUTER_SCORE + 1
            print('Computer won')
        elif human_choice == 'scissors' and computer_choice == 'paper':
            HUMAN_SCORE = HUMAN_SCORE + 1
            print('You win')
        elif human_choice == computer_choice:
            print("That was a tie")

1 Ответ

0 голосов
/ 06 июня 2019
import random


run = True

list = ["stone", "paper", "scissors"]

b_of = int(input("best out of : ? "))
print ("you win with", b_of, "pnt")

sc_p = 0
sc_c = 0 

while run == True:

    w_num = random.choice(list)

    guess = input("what's your choice")


    if guess == "stone" and w_num == "paper":
            sc_c = sc_c + 1
            print ( "paper, oups, computer wins with", sc_c, "pnt, and you have", sc_p, "pnt")

    elif guess == "stone" and w_num == "stone":
            print ( "stone, tie, computer has:", sc_c, "pnt, and you have", sc_p, "pnt")

    elif guess == "stone" and w_num == "scissors":
            sc_p = sc_p + 1
            print ( "scissors, you win, computer has", sc_c, "pnt, and you have", sc_p, "pnt")

    elif guess == "paper" and w_num == "paper":
            print ( "paper, tie, computer has:", sc_c, "pnt, and you have", sc_p, "pnt")

    elif guess == "paper" and w_num == "stone":
            sc_p = sc_p + 1
            print ( "stone, you win, computer has", sc_c, "pnt, and you have", sc_p, "pnt")

    elif guess == "paper" and w_num == "scissors":
            sc_c = sc_c + 1
            print ( "scissors, oups, computer wins with", sc_c, "pnt, and you have", sc_p, "pnt")

    elif guess == "scissors" and w_num == "paper":
            sc_p = sc_p + 1
            print (" paper, you win, computer has", sc_c, "pnt, and you have", sc_p, "pnt")

    elif guess == "scissors" and w_num == "stone":
            sc_c = sc_c + 1
            print ( "stone, oups, computer wins with", sc_c, "pnt, and you have", sc_p, "pnt")

    elif guess == "scissors" and w_num == "scissors":
            print ( "scissors, tie, computer has:", sc_c, "pnt, and you have", sc_p, "pnt")

    else:
            print ("enter a good value; stone, paper of scissors. computer has", sc_c, "pnt, and you have", sc_p, "pnt")


    if sc_c == b_of:
            print ("computer wins with", sc_c, "pnt!!!!")
            run = False

    elif sc_p == b_of:
            print ("you win with", sc_p, "pnt!!!!")
            run = False
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...