Jun-04-2020, 05:08 PM
Hello 
My second project is rock, paper, scissors which works with a "best of 3 rounds" mechanic.
Again, if anyone has a little time to spare could you go over my code to see how I've done please? I think my main concern is, have I over-complicated the process? I can't help but think 146 lines is overkill for rock, paper, scissors...?
Any input is very much appreciated, thank you.

My second project is rock, paper, scissors which works with a "best of 3 rounds" mechanic.
Again, if anyone has a little time to spare could you go over my code to see how I've done please? I think my main concern is, have I over-complicated the process? I can't help but think 146 lines is overkill for rock, paper, scissors...?
Any input is very much appreciated, thank you.
import random import time import sys # Options the computer can choose PCrps = [ 'Rock', 'Paper', 'Scissors' ] # Dictionary to convert player's guess so that it can be compared to computer's guess guessConvert = { 'Paper' : 'Rock', 'Rock' : 'Scissors', 'Scissors' : 'Paper', } # Created to reduce repetition later def guessRoutine(usr, pc): print('You guessed >> ', end='', flush=True) time.sleep(1.5) print(usr) time.sleep(1.5) print('Computer guessed >> ', end='', flush=True) time.sleep(1.5) print(pc) time.sleep(.5) # First fuction to run, the introduction def intro(q): print("Welcome to Rock, Paper, Scissors") time.sleep(1) print("Best of 3 rounds") time.sleep(1) print('Round 1') score1 = round1(q) # Counts the player's score by returing values from functions. score2 = round2(score1) # It works but could get messy if there were numerous iterations. # print(score2) For testing if score2 == 0: lost() elif score2 == 1: round3() else: won() def round1(q): while True: randrps = random.randint(0,2) pcguess = PCrps[randrps] # print(pcguess) For testing usrguess = (input('>>> ')).capitalize() if usrguess in PCrps: if usrguess == pcguess: guessRoutine(usrguess, pcguess) print('Draw! Try again\n') elif guessConvert[usrguess] == pcguess: guessRoutine(usrguess, pcguess) print('You won Round 1!\n') time.sleep(2) return q + 1 elif guessConvert[usrguess] != pcguess: guessRoutine(usrguess, pcguess) print('Oh dear! You lost!\n') return q else: print('Please type either "rock", "paper" or "scissors"\n') def round2(q): if q == 1: print('Round 2! Beat the computer and win the game! No pressure...') else: print('Round 2! You must win this round to be in with a chance of winning the game.') while True: randrps = random.randint(0,2) pcguess = PCrps[randrps] # print(pcguess) For testing usrguess = (input('>>> ')).capitalize() if usrguess in PCrps: if usrguess == pcguess: guessRoutine(usrguess, pcguess) print('Draw! Try again\n') elif guessConvert[usrguess] == pcguess: guessRoutine(usrguess, pcguess) print('You won Round 2!\n') time.sleep(2) return q + 1 elif guessConvert[usrguess] != pcguess: guessRoutine(usrguess, pcguess) print('Oh dear! You lost!\n') return q else: print('Please type either "rock", "paper" or "scissors"\n') def round3(): print('Round 3! Winner takes all!') while True: randrps = random.randint(0,2) pcguess = PCrps[randrps] # print(pcguess) For testing usrguess = (input('>>> ')).capitalize() if usrguess in PCrps: if usrguess == pcguess: guessRoutine(usrguess, pcguess) print('Draw! Try again\n') elif guessConvert[usrguess] == pcguess: guessRoutine(usrguess, pcguess) print('You won Round 3!') time.sleep(2) won() elif guessConvert[usrguess] != pcguess: guessRoutine(usrguess, pcguess) print('Oh dear! You lost!\n') lost() else: print('Please type either "rock", "paper" or "scissors"\n') # Funtion runs if player wins def won(): print('...and', end='', flush=True) time.sleep(1.5) print(' you won the game! Congratulations!') time.sleep(2) while True: playagain = input('Play again? y/n\n>>> ') if playagain.lower() == 'y': intro(0) elif playagain.lower() == 'n': sys.exit() else: print('Please type "y" or "n"') # Function runs if player loses def lost(): while True: playagain = input('\nPlay again? y/n\n>>> ') if playagain.lower() == 'y': intro(0) elif playagain.lower() == 'n': sys.exit() else: print('Please type "y" or "n"') # This runs the whole game, and initialises 'q' with 0 to reset the player's score intro(0)Thanks for reading.
