Python Forum
Why am I getting this TypeError Exception?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why am I getting this TypeError Exception?
#3
Full program:

import random

moves = ["rock", "paper", "scissors"]

def get_choices():
    player_choice = input("Enter a choice of rock, paper, or scissors: ")
    computer_choice = random.choice(moves)

    choices = {"player": player_choice, "computer": computer_choice}

    return choices 

def check_win(player, computer):
    print("You chose " + player + " and the computer chose " + computer)
    if player == computer:  
        return "It's a tie"
    
    elif player == "rock":
        if computer == "scissors":
            return "Rock beats scissors"
        else:
            return "Paper beats rock"
        
    elif player == "paper":
        if computer == "rock":
            return "Paper beasts rock"
        else:
            return "Scissors beats paper"
        
    elif player == "scissors":
        if computer == "paper":
            return "Scissors beats paper"
        else:
            return "Rocks beats scissors"
    
    
choices = get_choices()

results = check_win(choices["player"],choices["computer"])

print(results)
deanhystad write Jul-05-2023, 03:28 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply


Messages In This Thread
RE: Why am I getting this TypeError Exception? - by Affinity - Jul-05-2023, 03:24 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  During handling of the above exception, another exception occurred Skaperen 7 27,109 Dec-21-2018, 10:58 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020