I just recently started learning how to program and how to use python and after watching a few courses I made a simple Rock paper scissors game where basically the script randomly chooses Rock, paper or scissors then you make your choice and depending on what the program picked and what you picked you either win, lose or tie. This goes on until either you lose 3 times or win 3 times after which you'll be prompted for a rematch.
I was wondering how good is the code, I'd like Feedback as I want to know what I could have done differently to make the code better, cleaner and so on since I'm sure the code can be improved. I'll be using this sort of as a learning experience so I can better my programming knowledge.
import random
import time
import os
os.system("")
global vic_count
vic_count = 0
global loss_count
loss_count = 0
start = True
global rematchh
rematchh = True
CRED = '\033[91m'
CYEL = '\033[33m'
CGRE = '\033[32m'
CBLU = '\033[34m'
CTIL = '\033[3m'
CEND = '\033[0m'
def game_countinue():
global vic_count
global loss_count
global rematchh
while True:
rematch = input("REMATCH? Y/N: ").upper()
if rematch == "Y":
vic_count = 0
loss_count = 0
rematchh = False
return rematchh
elif rematch == "N":
break
def vcount():
global vic_count
vic_count += 1
ccount()
def lcount():
global loss_count
loss_count += 1
ccount()
def ccount():
print(CBLU + f"Player: {vic_count} Computer: {loss_count}" + CEND)
def bot():
bot_choice = ['Scissors', 'Paper', 'Rock']
bot_final_choice = random.choice(bot_choice)
return bot_final_choice
def player():
while True:
player_choice = input(CTIL + "(R)ock, (P)aper or (S)cissors: " + CEND).upper()
if player_choice == "P" and botchoice == "Scissors":
time.sleep(1)
print("Players choice: Paper")
time.sleep(1)
print("Computers choice: " + botchoice)
time.sleep(1)
print(CRED + 'You lose!' + CEND)
lcount()
break
elif player_choice == "P" and botchoice == "Rock":
time.sleep(1)
print("Players choice: Paper")
time.sleep(1)
print("Computers choice: " + botchoice)
time.sleep(1)
print(CGRE + 'You win!' + CEND)
vcount()
break
elif player_choice == "P" and botchoice == "Paper":
time.sleep(1)
print("Players choice: Paper")
time.sleep(1)
print("Computers choice: " + botchoice)
time.sleep(1)
print(CYEL + 'Tie!' + CEND)
ccount()
break
if player_choice == "R" and botchoice == "Paper":
time.sleep(1)
print("Players choice: Rock")
time.sleep(1)
print("Computers choice: " + botchoice)
time.sleep(1)
print(CRED + 'You lose!' + CEND)
lcount()
break
elif player_choice == "R" and botchoice == "Scissors":
time.sleep(1)
print("Players choice: Rock")
time.sleep(1)
print("Computers choice: " + botchoice)
time.sleep(1)
print(CGRE + 'You win!' + CEND)
vcount()
break
elif player_choice == "R" and botchoice == "Rock":
time.sleep(1)
print("Players choice: Rock")
time.sleep(1)
print("Computers choice: " + botchoice)
time.sleep(1)
print(CYEL + 'Tie!' + CEND)
ccount()
break
if player_choice == "S" and botchoice == "Rock":
time.sleep(1)
print("Players choice: Scissors")
time.sleep(1)
print("Computers choice: " + botchoice)
time.sleep(1)
print(CRED + 'You lose!' + CEND)
lcount()
break
elif player_choice == "S" and botchoice == "Paper":
time.sleep(1)
print("Players choice: Scissors")
time.sleep(1)
print("Computers choice: " + botchoice)
time.sleep(1)
print(CGRE + 'You win!' + CEND)
vcount()
break
elif player_choice == "S" and botchoice == "Scissors":
time.sleep(1)
print("Players choice: Scissors")
time.sleep(1)
print("Computers choice: " + botchoice)
time.sleep(1)
print(CYEL + 'Tie!' + CEND)
ccount()
break
while start == True:
yes_or_no = input(CRED + "WARNING!!! THIS GAME IS SO HARD THAT IT WILL PHYSICALLY CHANGE YOUR BEING, THIS IS ONLY MEANT FOR THE TRULY HARDENED GAMERS, ARE YOU SURE YOU WANT TO CONTINUE? Y/N: " + CEND).upper()
if yes_or_no == "N":
break
elif yes_or_no == "Y":
time.sleep(1)
print(CYEL + "WIN A FRIENDLY GAME OF ROCK PAPER SCISSORS, THE FIRST ONE TO GET 3 POINTS WINS!" + CEND)
time.sleep(3)
start = False
rematchh = False
while start == False and rematchh == False:
botchoice = bot()
print("Choosing..")
time.sleep(1)
print("Done choosing..")
time.sleep(1)
player()
time.sleep(1)
if vic_count >= 3:
print(CYEL + "CONGRATULATIONS!" + CEND)
rematchh = True
game_countinue()
elif loss_count >= 3:
print(CRED + "YOU SURE GOT RAZZLE DAZZLED!" + CEND)
rematchh = True
game_countinue()
I'm sure the code can be improved, especially with detecting what the player chose and the computer chose to determine who wins, as I ended up just using a ton of if
and elif
statements that just clutter everything.