Snake Water Gun Fun Program with SCOREBOARD #Python
import random
from prettytable import PrettyTable
code = ["s","g","w"]
codeValue = {"s": "Snake",
"g" : "Gun",
"w" : "Water"}
computerScore = 0
userScore = 0
# scoreboard
scoreboard = PrettyTable(["Computer's Score", "Your Score"])
# game logic
play = int(input("Enter number of matches you want to play : "))
while(True):
computerChoice = codeValue[random.choice(code)]
userCode = input("Enter your Choice : ")
userChoice = codeValue[userCode.lower()]
if(userChoice == computerChoice):
print(f"Your Choice = {userChoice}\nComputer's Choice = {computerChoice}\n")
print("--TIE--\n")
elif(userChoice == "Snake" and computerChoice == "Gun"):
print(f"Your Choice = {userChoice}\nComputer's Choice = {computerChoice}\n")
print("BAD LUCK!!\n")
computerScore = computerScore + 1
scoreboard.add_row([1, 0])
elif(userChoice == "Water" and computerChoice == "Snake"):
print(f"Your Choice = {userChoice}\nComputer's Choice = {computerChoice}\n")
print("BAD LUCK!!\n")
computerScore = computerScore + 1
scoreboard.add_row([1, 0])
elif(userChoice == "Gun" and computerChoice == "Water"):
print(f"Your Choice = {userChoice}\nComputer's Choice = {computerChoice}\n")
print("BAD LUCK!!\n")
computerScore = computerScore + 1
scoreboard.add_row([1, 0])
else:
print(f"Your Choice = {userChoice}\nComputer's Choice = {computerChoice}\n")
print("NICE MOVE!!\n")
userScore = userScore + 1
scoreboard.add_row([0, 1])
play = play -1
if(play == 0):
scoreboard.add_row([f"= {computerScore}", f"= {userScore}"])
print("----SCOREBOARD----\n")
print(scoreboard)
print("\n")
if(userScore > computerScore):
print("CONGRATULATIONS!! YOU WON!!\n")
elif(userScore < computerScore):
print("BETTER LUCK NEXT TIME!!\n")
else:
print("TIE!! You should go for another chance...\n")
key = input("Enter Q to quit or any other key to Continue...\n")
if(key.lower() == 'q'):
print("THANKS FOR PLAYING\n")
break
else:
play = int(input("Enter number of matches you want to play : "))
userScore = 0
computerScore = 0
Comments
Post a Comment