Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Practice coding (rock,paper,scissors

import random


def play():
    user = input("What's your choice? 'r' for rock, 'p' for paper, 's' for scissors\n")
    computer = random.choice(['r', 'p', 's'])

    if user == computer:
        return "It's a tie"

    if is_win(user, computer):
        return 'You won!'

    return 'You lost!'

def is_win(player, opponent):

    if(player == 'r' and opponent == 's') or (player == 's' and opponent == 'p')\
       or (player == 'p' and opponent == 'r'):
         return True

    # r > s, s > p, p > r,

Hi everyone,

I’m new here. I’m also new to python, currently practicing coding. can you help me with this code? If i run it, the output is blank. Thanks

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

It seems like your code is missing a main function that calls the play function and handles the output. Additionally, there are some issues with the indentation and structure of your code.

import random

def play():
    user = input("What's your choice? 'r' for rock, 'p' for paper, 's' 
for scissors\n")
    computer = random.choice(['r', 'p', 's'])

    if user == computer:
        return "It's a tie"

    if is_win(user, computer):
        return 'You won!'

    return 'You lost!'

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

result = play()
print(result)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading