-1
import random
import time


# start = input('Do you want to play a game of rock, paper, scissors? (Y/Yes or N/No) \n').lower()
# if start == 'y' or 'yes':
def play():
    user = input("Would you like to play 'R/Rock', 'P/Paper', or 'S/Scissors'? \n").lower()
    if user == 'p':
        user = 'paper'
    elif user == 'r':
        user = 'rock'
    elif user == 's':
        user = 'scissors'

    print(f'You played {user}!')

    computer = random.choice(['rock', 'paper', 'scissors'])
    print(f'The computer played {computer}!')
    time.sleep(0.5)

    if user == computer:
        return 'Tie game!'

    if win_condition(user, computer):
        return 'You win!'

    return 'You lost :('


def win_condition(player, bot):
    if (player == 'r' or 'rock' and bot == 'scissors') or (player == 's' or 'scissors' and bot == 'paper') or \
            (player == 'p' or 'paper' and bot == 'rock'):
        return True


# elif start == 'n' or 'no':
# quit()


print(play())

I have a couple of questions. First off, sometimes I keep on getting 'You win!' as my result even when I supposedly lose and I am not sure why. Second, how can I make it so that the entire program runs my function if I type 'y' or 'yes' and exits if I say 'n' or 'no' in the beginning (comments in lines 5 and 37). I tried running it where the comments are with an if and elif at the end, but it did not work. A brief explanation would also be very helpful! I am still very new to Python and am still trying to learn/strengthen the basics so I apologize if it's something very obvious and I miss it. If possible, please keep it in more basic/generalized syntax as I do not know the ones past a beginner level. Thank you in advance!

dc_
  • 1
  • you are not covering a case where the user inputs something else than "p", "r" or "s". Then you should put the "You lost" in an else clause, otherwise it will always be displayed. It would be better to let the function winning condition do all the work, and determine if player wins, computer wins or there;s a tie. – Sembei Norimaki Jun 02 '22 at 08:56
  • Change `(player == 'r' or 'rock' and bot == 'scissors')` to `(player in ('r', 'rock') and bot == 'scissors')` – CN-LanBao Jun 02 '22 at 08:57

0 Answers0