jeudi 23 avril 2020

How to use random to generate different string answers for a game

When I call computer.guess(). It doesn't generate a R, S, or P like I thought it would. Any hints on what I did wrong? I do have random imported into the script and when I run it in the command line. It does not return anything back to me

class Computer:
    def __init__(self):
        self.winning = True
        self.game_over = False

    def guess(self):
        if random.randint(0,2) == 0:
            return 'R'
            print('Computer chose R')
        elif random.randint(0,2) == 1:
            return 'P'
            print('Computer chose P')
        else:
            return 'S'
            print('Computer chose S')

    def win(self):

        if guess == 'S' and player.guess == 'P':
            self.winning
            print('Computer is the winner!')
        if guess == 'R' and player.guess == 'S':
            self.winning
            print('Computer is the winner!')
        if guess == 'P' and player.guess == 'R':
            self.winning
            print('Computer is the winner!')

    def computer_lose(self):

        if player.win == winning:
            print('Computer has lost')
            self.game_over = True
            self.winning = False



Aucun commentaire:

Enregistrer un commentaire