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()
Aucun commentaire:
Enregistrer un commentaire