├── README.md └── Stone Paper Scissors /README.md: -------------------------------------------------------------------------------- 1 | It's a python code. 2 | It's a Stone Paper Scissors game code 3 | It has 3 option 1 - Stone 4 | 2 - Paper 5 | 3 - Scissors 6 | It ask us to select the valid no from above given. 7 | 8 | -------------------------------------------------------------------------------- /Stone Paper Scissors: -------------------------------------------------------------------------------- 1 | # import random module 2 | import random 3 | # print multiline instruction 4 | # performstring concatenation of string 5 | print('Winning rules of the game ROCK PAPER SCISSORS are :\n' 6 | + "Rock vs Paper -> Paper wins \n" 7 | + "Rock vs Scissors -> Rock wins \n" 8 | + "Paper vs Scissors -> Scissor wins \n") 9 | 10 | while True: 11 | 12 | print("Enter your choice \n 1 - Rock \n 2 - Paper \n 3 - Scissors \n") 13 | 14 | # take the input from user 15 | 16 | choice = int(input("Enter your choice :")) 17 | 18 | # OR is the short-circuit operator 19 | # if any one of the condition is true 20 | # then it return True value 21 | 22 | # looping until user enter invalid input 23 | while choice > 3 or choice < 1: 24 | choice = int(input('Enter a valid choice please ☺')) 25 | 26 | # initialize value of choice_name variable 27 | # corresponding to the choice value 28 | if choice == 1: 29 | choice_name = 'Rock' 30 | elif choice == 2: 31 | choice_name = 'Paper' 32 | else: 33 | choice_name = 'Scissors' 34 | 35 | # print user choice 36 | print('User choice is \n', choice_name) 37 | print('Now its Computers Turn....') 38 | 39 | # Computer chooses randomly any number 40 | # among 1 , 2 and 3. Using randint method 41 | # of random module 42 | comp_choice = random.randint(1, 3) 43 | 44 | # looping until comp_choice value 45 | # is equal to the choice value 46 | while comp_choice == choice: 47 | comp_choice = random.randint(1, 3) 48 | 49 | # initialize value of comp_choice_name 50 | # variable corresponding to the choice value 51 | if comp_choice == 1: 52 | comp_choice_name = 'RocK' 53 | elif comp_choice == 2: 54 | comp_choice_name = 'Paper' 55 | else: 56 | comp_choice_name = 'Scissors' 57 | print("Computer choice is \n", comp_choice_name) 58 | print(choice_name, 'Vs', comp_choice_name) 59 | # we need to check of a draw 60 | if choice == comp_choice: 61 | print('Its a Draw', end="") 62 | result = "DRAW" 63 | # condition for winning 64 | if (choice == 1 and comp_choice == 2): 65 | print('paper wins =>', end="") 66 | result = 'Paper' 67 | elif (choice == 2 and comp_choice == 1): 68 | print('paper wins =>', end="") 69 | result = 'Paper' 70 | 71 | if (choice == 1 and comp_choice == 3): 72 | print('Rock wins =>\n', end="") 73 | result = 'Rock' 74 | elif (choice == 3 and comp_choice == 1): 75 | print('Rock wins =>\n', end="") 76 | result = 'RocK' 77 | 78 | if (choice == 2 and comp_choice == 3): 79 | print('Scissors wins =>', end="") 80 | result = 'Scissors' 81 | elif (choice == 3 and comp_choice == 2): 82 | print('Scissors wins =>', end="") 83 | result = 'Rock' 84 | # Printing either user or computer wins or draw 85 | if result == 'DRAW': 86 | print("<== Its a tie ==>") 87 | if result == choice_name: 88 | print("<== User wins ==>") 89 | else: 90 | print("<== Computer wins ==>") 91 | print("Do you want to play again? (Y/N)") 92 | # if user input n or N then condition is True 93 | ans = input().lower() 94 | if ans == 'n': 95 | break 96 | # after coming out of the while loop 97 | # we print thanks for playing 98 | print("thanks for playing") 99 | --------------------------------------------------------------------------------