|
| 1 | +#My Rock Paper Scissor Game # |
| 2 | +import random |
| 3 | + |
| 4 | +print("Winning Rules of the Rock paper scissor game as follows: \n" |
| 5 | + +"Rock vs paper->paper wins \n" |
| 6 | + + "Rock vs scissor->Rock wins \n" |
| 7 | + +"paper vs scissor->scissor wins \n") |
| 8 | + |
| 9 | +while True: |
| 10 | + print("Enter choice \n 1 for Rock, \n 2 for paper, and \n 3 for scissor \n") |
| 11 | + |
| 12 | + |
| 13 | + choice = int(input("User turn: ")) |
| 14 | + |
| 15 | + while choice > 3 or choice < 1: |
| 16 | + choice = int(input("enter valid input: ")) |
| 17 | + |
| 18 | + |
| 19 | + if choice == 1: |
| 20 | + choice_name = 'Rock' |
| 21 | + elif choice == 2: |
| 22 | + choice_name = 'paper' |
| 23 | + else: |
| 24 | + choice_name = 'scissor' |
| 25 | + |
| 26 | + |
| 27 | + print("user choice is: " + choice_name) |
| 28 | + print("\nNow its computer turn.......") |
| 29 | + |
| 30 | + |
| 31 | + comp_choice = random.randint(1, 3) |
| 32 | + |
| 33 | + while comp_choice == choice: |
| 34 | + comp_choice = random.randint(1, 3) |
| 35 | + |
| 36 | + |
| 37 | + if comp_choice == 1: |
| 38 | + comp_choice_name = 'Rock' |
| 39 | + elif comp_choice == 2: |
| 40 | + comp_choice_name = 'paper' |
| 41 | + else: |
| 42 | + comp_choice_name = 'scissor' |
| 43 | + |
| 44 | + print("Computer choice is: " + comp_choice_name) |
| 45 | + |
| 46 | + print(choice_name + " V/s " + comp_choice_name) |
| 47 | + |
| 48 | + if choice == comp_choice: |
| 49 | + print("Draw=> ", end = "") |
| 50 | + result = Draw |
| 51 | + |
| 52 | + |
| 53 | + if((choice == 1 and comp_choice == 2) or |
| 54 | + (choice == 2 and comp_choice ==1 )): |
| 55 | + print("paper wins => ", end = "") |
| 56 | + result = "paper" |
| 57 | + |
| 58 | + elif((choice == 1 and comp_choice == 3) or |
| 59 | + (choice == 3 and comp_choice == 1)): |
| 60 | + print("Rock wins =>", end = "") |
| 61 | + result = "Rock" |
| 62 | + else: |
| 63 | + print("scissor wins =>", end = "") |
| 64 | + result = "scissor" |
| 65 | + |
| 66 | + |
| 67 | + if result == Draw: |
| 68 | + print("<== Its a tie ==>") |
| 69 | + if result == choice_name: |
| 70 | + print("<== User wins ==>") |
| 71 | + else: |
| 72 | + print("<== Computer wins ==>") |
| 73 | + |
| 74 | + print("Do you want to play again? (Y/N)") |
| 75 | + ans = input().lower |
| 76 | + |
| 77 | + |
| 78 | + |
| 79 | + if ans == 'n': |
| 80 | + break |
| 81 | + |
| 82 | +print("\nThanks for playing") |
| 83 | + |
| 84 | + |
| 85 | + |
| 86 | + |
| 87 | +Output:- |
| 88 | + |
0 commit comments