Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- user_score = 0
- computer_score = 0
- POSSIBILITIES = ["paintbrush", "canvas", "palette"]
- def get_player_name():
- user_name = input("Hey there! What's your name? ")
- print(f"Whoa! {user_name} is a gorgeous name!")
- return user_name
- def get_player_choice():
- # Use input() to ask the user to choose rock, paper, or scissors
- user_choice = input("paintbrush, canvas, or palette? ").lower()
- # Store their answer in a variable
- # Return that variable
- if user_choice not in POSSIBILITIES:
- print("Sorry, I don't think that's an option. Please try again and check your spelling.")
- return user_choice
- # Replace pass with your code
- def choose_computer_move():
- computer_move = random.choice(POSSIBILITIES)
- # Use random.choice(POSSIBILITIES) to pick a random move
- # Return that move
- return computer_move
- # Replace pass with your code
- def decide_winner(user_choice, computer_move, user_name, user_score, computer_score):
- # Figure out who won using if/elif/else
- # Rules: paint brush beats canvas, canvas beats palette, palette beats paint brush
- if computer_move == user_choice:
- print("It's a tie!")
- return "tie"
- elif computer_move == "paintbrush" and user_choice == "palette":
- print("You won? The computer shall seek its revenge!")
- user_score += 1
- return "player"
- elif computer_move == "palette" and user_choice == "canvas":
- print("You won! Well... Beginner's luck. The computer shall triumph!")
- user_score += 1
- return "player"
- elif computer_move == "canvas" and user_choice == "paintbrush":
- print(f"HOW DARE YOU WIN AGAINST THE ALL POWERFUL COMPUTER! WITCHCRAFT! YOU CANNOT ESCAPE ME {user_name}!!!")
- user_score += 1
- return "player"
- elif computer_move == "palette" and user_choice == "paintbrush":
- print(f"You lost. Don't worry, {user_name}. There's always next time!")
- computer_score += 1
- return "computer"
- elif computer_move == "canvas" and user_choice == "palette":
- print(f"Uh oh, you lost :( Don't fret, {user_name}. There's always next time!")
- computer_score += 1
- return "computer"
- elif computer_move == "paintbrush" and user_choice == "canvas":
- print(f"You lost? Better luck next time, {user_name}.")
- computer_score += 1
- return "computer"
- # If both picked the same thing, return the string 'tie'
- # If the player won, return the string 'player'
- # If the computer won, return the string 'computer'
- # Replace pass with your code
- def play_one_round():
- user_name = get_player_name()
- player = get_player_choice()
- computer = choose_computer_move()
- winner = decide_winner(player, computer, user_name, computer_score, user_score)
- print(player)
- print(computer)
- print(winner)
- # Run the game
- play_one_round()
Advertisement
Add Comment
Please, Sign In to add comment