Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Can anyone review this?

fh1

Coder
Hello!!đź‘‹ So I made this rock paper scissors game and I wanted to see if anyone could preview it and maybe give some feedback or rate the game.
Python:
import random
yourPoints = 0
botPoints = 0
while True:
  choices = ["rock", "paper", "scissors"]
  botChoice = random.choice(choices)
  print("Rock, Paper, Scissors. Type them exactly how they are.")
  playerChoice = input("Type in your choice: ")
  playerChoice = playerChoice.lower()
  if playerChoice not in choices:
    print("Invalid input. Please enter rock, paper, or scissors.")
    continue
  print("Bot's choice:", botChoice)
  print("Your choice:", playerChoice)
  if botChoice == playerChoice:
    print(f"Both players used {playerChoice}. So it's a tie!")
    continue
  elif playerChoice == "scissors":
    if botChoice == "paper":
      print("You win because scissors beat paper!")
      yourPoints += 1
    else:
      print("You lost because rock crushes scissors.")
      botPoints += 1
  elif playerChoice == "rock":
    if botChoice == "scissors":
      print("You win because rock crushes scissors!")
      yourPoints += 1
    else:
      print("You lost because paper covers rock.")
      botPoints += 1
  elif playerChoice == "paper":
    if botChoice == "rock":
      print("You win because paper covers rock!")
      yourPoints += 1
    else:
      print("You lost because scissors cut paper.")
      botPoints += 1
  wannaPlay = input("Type Y to play again. Type N to end: ")
  wannaPlay = wannaPlay.lower()
  if wannaPlay not in ["y", "n"]:
    print("Invalid input. Please enter Y or N.")
    continue
  if wannaPlay == "n":
    break
print("Your points:", yourPoints)
print("Bot's points:", botPoints)
If anyone would like to do coding with me let me know (you’ll need replit)
 
I think the code works fine.

Here is one of my early attempts using functions and match case.

Python:
# Do the imports
from random import choice
import os

# Set some global variables
player_score = 0
computer_score = 0
ties = 0

def clear():
    ''' Function to clear the screen clutter '''
    os.system('cls' if os.name == 'nt' else 'clear')

def score(msg):
    ''' Function for displaying scores '''
    clear()
    print(f'Player: {player_score} | Computer: {computer_score} | Ties: {ties}')
    print(msg)

# Display the score at start
score(msg='Hello! Welcome to Rock, Paper Scissors.')

# Get the while loop started
while True:
    # Get player input
    play = input('Please type rock, paper, scissors and press enter.\n>> ')

    # Get a random choice for the computer
    pc = choice(['rock', 'paper', 'scissors'])

    # Check if player input is valid. If not go back to start
    if play not in ['rock', 'paper', 'scissors']:
        score('That is not a valid option. Please try again.')
        continue

    match play:
        # Match will check for player input then apply correct case
        # Here we also advance the correct player score if they win
        # We also have various message to be displayed depending on outcome
        case 'rock':
            if pc == 'scissors':
                msg = 'Rock smashes scissors - Player wins'
                player_score += 1
            elif pc == 'paper':
                msg = 'Paper covers rock - Computer wins'
                computer_score += 1
            else:
                msg = 'Tie Game'
                ties += 1
            score(msg)

        case 'paper':
            if pc == 'scissors':
                msg = 'Scissors cut paper - Computer wins.'
                computer_score += 1
            elif pc == 'rock':
                msg = 'Paper covers rock - Player wins'
                player_score += 1
            else:
                msg = 'Tie Game'
                ties += 1
            score(msg)

        case 'scissors':
            if pc == 'rock':
                msg = 'Rock smashes scissors - Computer wins'
                computer_score += 1
            elif pc == 'paper':
                msg = 'Scissors cut paper - Player wins.'
                player_score += 1
            else:
                msg = 'Tie Game'
                ties += 1
            score(msg)

        case _:
            print('unknown')
              
    # Ask if player wants to play again
    play_again = input('Play Again y/n: ').lower()
    if play_again == 'y':
        score(msg='')
    else:
        clear()
        score('Goodbye!')
        break
 
I found your code to be of a good solid quality. Good choice of variable names made the code easy to read.
It would benefit from some comments explaining the intention of each part, like mentor”s comments for match play: , but not to extent of explaining that while True starts a loop!
 
I found your code to be of a good solid quality. Good choice of variable names made the code easy to read.
It would benefit from some comments explaining the intention of each part, like mentor”s comments for match play: , but not to extent of explaining that while True starts a loop!
Thanks! I’ll add some comments :)
 

New Threads

Buy us a coffee!

Back
Top Bottom