|
| 1 | +import random |
| 2 | + |
| 3 | +us = 0 |
| 4 | +bs = 0 |
| 5 | + |
| 6 | +# Introduction |
| 7 | +print("Welcome to ROCK, PAPER , SCISSOR") |
| 8 | +print("The rule to winning is ->") |
| 9 | +print("Rock beats scissor, scissor beats paper and paper beats rock") |
| 10 | + |
| 11 | +# Getting player name |
| 12 | +print() |
| 13 | +player_name = input("Enter your name : ") |
| 14 | + |
| 15 | +print() |
| 16 | +# Getting name of opponent |
| 17 | +while True: |
| 18 | + namec = input("Would you like to name your opponent (default name is bot) (enter y/n) : ") |
| 19 | + if namec == "y": |
| 20 | + bot_name = input("Enter name of opponent : ") |
| 21 | + break |
| 22 | + elif namec == "n": |
| 23 | + bot_name = "bot" |
| 24 | + break |
| 25 | + else: |
| 26 | + print("Enter correct response") |
| 27 | + print() |
| 28 | + |
| 29 | +moves = ['rock', 'paper', 'scissor'] |
| 30 | + |
| 31 | + |
| 32 | +def check_winning(): |
| 33 | + if us > bs: |
| 34 | + print("You are currently winning, nice going.") |
| 35 | + elif us < bs: |
| 36 | + print("You are currently losing, but don't lose hope, tables might turn around soon.") |
| 37 | + elif us == bs: |
| 38 | + print("You score is currently tied with that of", bot_name, ",the match is neck to neck.") |
| 39 | + |
| 40 | + |
| 41 | +def printing_score(): |
| 42 | + print(player_name, "score :", us) |
| 43 | + print(bot_name, "score :", bs) |
| 44 | + |
| 45 | + |
| 46 | +def tie_display(): |
| 47 | + print("That's a tie. What a coincidence!!") |
| 48 | + print("Score remains unchanged, so score is ->") |
| 49 | + printing_score() |
| 50 | + check_winning() |
| 51 | + |
| 52 | + |
| 53 | +print() |
| 54 | +print("Let's begin!!") |
| 55 | +print() |
| 56 | + |
| 57 | +while True: |
| 58 | + user_input = input("Enter your move : ") |
| 59 | + bot_input = random.choice(moves) |
| 60 | + print(bot_name, " entered :", bot_input) |
| 61 | + print() |
| 62 | + |
| 63 | + if user_input == "rock" and bot_input == "rock": |
| 64 | + tie_display() |
| 65 | + |
| 66 | + elif user_input == "rock" and bot_input == "paper": |
| 67 | + print("You lost") |
| 68 | + bs = bs + 1 |
| 69 | + print(bot_name, "gained 1 point, so score is ->") |
| 70 | + printing_score() |
| 71 | + check_winning() |
| 72 | + |
| 73 | + elif user_input == "rock" and bot_input == "scissor": |
| 74 | + print("You won") |
| 75 | + us = us + 1 |
| 76 | + print("You gained 1 point, so score is ->") |
| 77 | + printing_score() |
| 78 | + check_winning() |
| 79 | + |
| 80 | + elif user_input == "paper" and bot_input == "rock": |
| 81 | + print("You won") |
| 82 | + us = us + 1 |
| 83 | + print("You gained 1 point, so score is ->") |
| 84 | + printing_score() |
| 85 | + check_winning() |
| 86 | + |
| 87 | + elif user_input == "paper" and bot_input == "paper": |
| 88 | + tie_display() |
| 89 | + |
| 90 | + elif user_input == "paper" and bot_input == "scissor": |
| 91 | + print("You lost") |
| 92 | + bs = bs + 1 |
| 93 | + print(bot_name, "gained 1 point, so score is ->") |
| 94 | + printing_score() |
| 95 | + check_winning() |
| 96 | + |
| 97 | + elif user_input == "scissor" and bot_input == "rock": |
| 98 | + print("You lost") |
| 99 | + bs = bs + 1 |
| 100 | + print(bot_name, "gained 1 point, so score is ->") |
| 101 | + printing_score() |
| 102 | + check_winning() |
| 103 | + |
| 104 | + elif user_input == "scissor" and bot_input == "paper": |
| 105 | + print("You won") |
| 106 | + us = us + 1 |
| 107 | + print("You gained 1 point, so score is ->") |
| 108 | + printing_score() |
| 109 | + check_winning() |
| 110 | + |
| 111 | + elif user_input == "scissor" and bot_input == "scissor": |
| 112 | + tie_display() |
| 113 | + |
| 114 | + else: |
| 115 | + print("Enter correct move") |
| 116 | + |
| 117 | + con = input("Want to continue game (y/n) : ") |
| 118 | + if con == "n": |
| 119 | + break |
| 120 | +print("The game is now finished.") |
| 121 | +print("The final result is given below ->") |
| 122 | +printing_score() |
| 123 | +if us > bs: |
| 124 | + print("You have officially defeated", bot_name, "!!! Congratulations on your victory") |
| 125 | +elif us < bs: |
| 126 | + print("Unfortunately you lost the game. But its alright. There is always a next time.") |
| 127 | +elif us == bs: |
| 128 | + print("The final result is a tie. It seems that both you and", bot_name, "are equally good at this game.") |
0 commit comments