Skip to content

natnew/Python-Projects-Rock-Paper-Scissors

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 

Repository files navigation

Python Projects Rock Paper Scissors 🐍

Python Script
This repo contains python code that generates a rock, paper, scissors game.
Run the code.

Python

import random

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

    if user == computer:
        return 'It is 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

print(play())

Output

You Won!

About

Python Projects Rock Paper Scissors

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages