🐞 Fixing Bugs | myBetabox

🐞 Fixing Bugs

Keyboard Guide

Fixing Bugs

Stuck? Copy & Paste the Code into Repl.it

import random

player_wins = 0
comp_wins = 0

playing = True

while playing:
  print("Welcome to RPS")
  player_choice = input("Do you pick [rock], [paper], or [scissors]?: ").lower()

  while player_choice not in ["rock", "paper", "scissors"]:
    print("That isn't an option, try again!")
    player_choice = input("Do you pick [rock], [paper], or [scissors]?: ").lower()

  comp_choice = random.choice(["rock", "paper", "scissors"])

  print("Player chose " + player_choice + " and Computer chose " + comp_choice)

  if player_choice == "rock" and comp_choice == "scissors":
    print("You Won! Congratulations!")
    player_wins += 1
  elif player_choice == "paper" and comp_choice == "rock":
    print("You Won! Congratulations!")
    player_wins += 1
  elif player_choice == "scissors" and comp_choice == "paper":
    print("You Won! Congratulations!")
    player_wins += 1
  elif player_choice == "rock" and comp_choice == "paper":
    print("You Lost! Try Again!")
    comp_wins += 1
  elif player_choice == "paper" and comp_choice == "scissors":
    print("You Lost! Try Again!")
    comp_wins += 1
  elif player_choice == "scissors" and comp_choice == "rock":
    print("You Lost! Try Again!")
    comp_wins += 1

  print("Player Wins: " + str(player_wins) + " - Computer Wins: " + str(comp_wins))

  stop = ""

  while stop not in ["y", "n"]:
    stop = input("Would you like to stop playing [y]/[n]?: ").lower()

  if stop == "y":
    playing = False
    print("Thank you for playing!")

The Code Explained

What happens if I type something that’s not rock, paper, or scissors…like spaghetti?

You can program your game to say something when a player types a word not found in the list of valid selections. Then the game will repeat the original question.

 while player_choice not in ["rock", "paper", "scissors"]:
    print("That isn't an option, try again!")
    player_choice = input("Do you pick [rock], [paper], or [scissors]?: ")

I typed Rock/Paper/Scissors but it didn’t work!

If you coded your game withΒ rock but typed Rock, ROCK, rOcK, etc… the computer won’t recognize those as valid entries. Think of it like training your dog to sit. Your pup has practiced and learned to sit when you say “Sit!” but it won’t understand if you say “squat” or “stay put” even it they mean the same to you.

Is there a way to make words with random capitalization work?

Yes! Add a lower() function at the end of your player_choice = input function to turn all typed choices automatically into lowercase. So even if someone types RoCK, and you coded your game withΒ rock, then it will work.

player_choice = input("Do you pick [rock], [paper], or [scissors]?: ").lower()