How can I insert a continuous loop into this code?

Question:

How can I loop this code to make it continue playing with computer?

def play():
    print(f"What's your Choice?. n'r' for Rock, n'p' for Paper, n's' for Scissors.")
    
        user = input(f'You Choose:')
        computer =random.choice(['r','p','s'])
    
        if user == computer:
            return "It's a tie"
    
        if is_win(user, computer):
            return 'You Win.'
    
        return 'You Lose.'

def is_win(player, machine):
    if (player == 'p' and machine =='r') or (player =='r' and machine=='s') or (player =='s' and machine =='p'):
         return True

I’m expecting to play with computer continuously

Asked By: Ziero

||

Answers:

import random

while True:
    user = input('Choose rock (r), paper (p), or scissors (s): ')
    computer = random.choice(['r', 'p', 's'])

    if user == computer:
        print("It's a tie!")
    elif (user == 'r' and computer == 's') or (user == 'p' and computer == 'r') or (user == 's' and computer == 'p'):
        print('You win!')
    else:
        print('You lose!')

    play_again = input('Do you want to play again? (y/n): ')
    if play_again.lower() != 'y':
        break
Answered By: Nirmal Pandey
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.