Keyboard Guide
import random player_wins = 0 comp_wins = 0 ties = 0 playing = True while playing: print("Welcome to RPS") print("This is a text version of the popular game.") print("Play by typing in either rock, paper, or scissors when prompted.") print("Rock crushes scissors, paper covers rock, and scissors cuts paper.") 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 elif player_choice == comp_choice: print("You Tied! Try Again!") ties += 1 print("Player Wins: " + str(player_wins) + " - Computer Wins: " + str(comp_wins) + " - Ties: " + str(ties)) 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!")
Now it’s time for you to switch up some elements in your game!
If you want to make your game about something else, like animals (bird, turtle, dog), then replace those words in your game. Make sure your elif conditions make sense when changing it up.
First add a ties variable to keep track of the number of ties in your game.
ties = 0
Next, increment the tied score value if the player_choice is the same as the comp_choice.
elif player_choice == comp_choice: print("You Tied! Try Again!") ties += 1
Then, add and concatenate strings to the score tracker.
print("Player Wins: " + str(player_wins) + " - Computer Wins: " + str(comp_wins) + " - Ties: " + str(ties))
Use the print() function to create more in-game messages. You can write anything from instructions, backstories, or fun facts. Remember to use quotation marks inside the parentheses when writing sentences for strings.
print("Rock crushes scissors, paper covers rock, and scissors cuts paper.")