0

Python beginner here. I'm trying to troubleshoot a program that is a simple "rock, paper, scissors" game. However, the code stops running after it outputs "Computer choice is (x)". Is the error in the functions or in the module?

I'm using a custom module as well.

Module:

    print('      Menu')
    print('A.)   Rock')
    print('B.)   Paper')
    print('C.)   Scissors')

Code:

import random
def main():
    """The purpose of the main function is to take the user's input, validate it then compare it to the computer's generated answer to find the winner."""
   
    gamesfunctions()
    while True:
        user_choice = input("Enter choice: ")
        if user_choice.lower() not in ('a', 'b', 'c', 'd') and user_choice.upper() not in ('A', 'B', 'C', 'D'):
            print("Not an appropriate choice.")
            continue
        else:
            break
           
    computer_choice = generate_computer_value()
    check_winner(user_choice, computer_choice)
 

def generate_computer_value():
    computer_value = random.randint(1,3)
    return computer_value

def check_winner(user_choice, computer_value):
    if computer_value == 1:
        computer_value == "A" or computer_value == "a"
        print("Computer choice is rock")
    elif computer_value == 2:
        computer_value == "B" or computer_value == "b"
        print("Computer choice is paper")
    elif computer_value == 3:
        computer_value == "C" or computer_value == "c"
        print("Computer choice is scissors")
    elif user_choice == computer_value:
        print('Same answer try again')
    elif user_choice == "Rock" and computer_value == "C":
        print('Rock smashes scissors, the game ends')
    elif user_choice == "Scissors" and computer_value == "B":
        print('Scissors cut paper, the game ends')
    elif user_choice == "Paper" and computer_value == "A":
        print('Paper wraps rock, the game ends')
    elif computer_value == "A" and user_choice == "Scissors":
        print('Rock smashes scissors, the game ends')
    elif computer_value == "3" and user_choice == "Paper":
        print('Scissors cut paper, the game ends')
    else:
        print('Paper wraps rock, the game ends')

main()
3
  • 1
    computer_value == "A" or computer_value == "a" What is the point of this line? It doesn't do anything. And what's more, those conditions can't ever be true, because that line is indented underneath if computer_value == 1. Commented Jan 12, 2021 at 23:41
  • What's gamesfunctions? Commented Jan 12, 2021 at 23:41
  • @Countour-Integral it is the custom module. Sorry I didn't mention the name of the module Commented Jan 12, 2021 at 23:43

2 Answers 2

2

The line

elif user_choice == computer_value: 

Should be an if

Sign up to request clarification or add additional context in comments.

Comments

0

However, the code stops running after it outputs "Computer choice is (x)". Is the error in the functions or in the module

It does that because you have not told your code to keep repeating. You can make it infinitely loop easily.

while True:
    main()

2 Comments

He was asking why the Rock smashes scissors, the game ends etc. messages didn't appear. He wasn't expecting the game to repeat.
@John Gordon In fact, they could have also meant that. The expression python code stops will probably not make you think they are talking about why an if ,else is not executed. The question should have been more clear.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.