├── README.md ├── main.py └── main_short.py /README.md: -------------------------------------------------------------------------------- 1 | # Snake-Water-Gun-Game -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | ''' 2 | 1 for snake 3 | -1 for water 4 | 0 for gun 5 | ''' 6 | import random 7 | 8 | computer = random.choice([-1, 0, 1]) 9 | youstr = input("Enter your choice: ") 10 | youDict = {"s": 1, "w": -1, "g": 0} 11 | reverseDict = {1: "Snake", -1 : "Water", 0 : "Gun"} 12 | you = youDict[youstr] 13 | 14 | print(f"you chose {reverseDict[you]} \nComputer chose {reverseDict[computer]}") 15 | 16 | if (computer == you) : 17 | print("It's a draw") 18 | else : 19 | if (computer == -1 and you == 1): 20 | print("you win") 21 | elif (computer == -1 and you == 0): 22 | print("You Lose") 23 | elif (computer == 1 and you == -1): 24 | print("you lose") 25 | elif (computer == 1 and you == 0): 26 | print("You Win") 27 | elif (computer == 0 and you == -1): 28 | print("you win") 29 | elif (computer == 0 and you == 1): 30 | print("You Lose") 31 | else : 32 | print("Something went wrong!") 33 | -------------------------------------------------------------------------------- /main_short.py: -------------------------------------------------------------------------------- 1 | ''' 2 | 1 for snake 3 | -1 for water 4 | 0 for gun 5 | ''' 6 | import random 7 | 8 | computer = random.choice([-1, 0, 1]) 9 | youstr = input("Enter your choice: ") 10 | youDict = {"s": 1, "w": -1, "g": 0} 11 | reverseDict = {1: "Snake", -1 : "Water", 0 : "Gun"} 12 | you = youDict[youstr] 13 | 14 | print(f"you chose {reverseDict[you]} \nComputer chose {reverseDict[computer]}") 15 | 16 | if (computer == you) : 17 | print("It's a draw") 18 | else : 19 | ''' 20 | if (computer == -1 and you == 1): (computer - you) = -2 21 | print("you win") 22 | elif (computer == -1 and you == 0): (computer - you) = -1 23 | print("You Lose") 24 | elif (computer == 1 and you == -1): (computer - you) = 2 25 | print("you lose") 26 | elif (computer == 1 and you == 0): (computer - you) = 1 27 | print("You Win") 28 | elif (computer == 0 and you == -1): (computer - you) = 1 29 | print("you win") 30 | elif (computer == 0 and you == 1): (computer - you) = -1 31 | print("You Lose") 32 | else : 33 | print("Something went wrong!") 34 | 35 | The below logic is written on the basic of the value of computer - you 36 | ''' 37 | if ((computer - you) == -1 or (computer - you) == 2) : 38 | print("you lose") 39 | else : 40 | print("you win") 41 | --------------------------------------------------------------------------------