Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

rock paper scissors game in python

import random
choices = ['r', 's', 'p']
choice_meaning = {
    'r': 'Rock',
    's': 'Scissors',
    'p': 'Paper'
}
ai_choice = random.choice(choices)

user_choice = input('Enter your choice as r = Rock, s= scissors, p= paper : ')

if user_choice in choices:
    print(
        f"Your choice is {choice_meaning[user_choice]}.Computer choice is {choice_meaning[ai_choice]}.")
    if user_choice == ai_choice:
        print("Tie")
    elif (user_choice == 'r' and ai_choice == 's') or (user_choice == 's' and ai_choice == 'p') or (user_choice == 'p' and ai_choice == 'r'):
        print("You won")
    else:
        print("You lost")
else:
    print("Invalid inpute")
 
PREVIOUS NEXT
Tagged: #rock #paper #scissors #game #python
ADD COMMENT
Topic
Name
8+3 =