Henoke
Henoke

Reputation: 1

Incorrect results in the Rock-paper-scissors game on Python

I want to write a Rock-paper-scissors game in Python. I wrote the code, but I have a problem. When there should be a total of the game I have the program just lists the possible answers of the program. Not the ones that should be. Who doesn't mind, take a look please. I'm a beginner and it's hard for me to find the error. I already tried to change the code by playing with the while loop, if else conditions. Nothing works. Below is all the code I wrote. Help me out here please.

import random

#Список КНБ
knb = ["stone", "scissors", "paper"]

print('Welcome to the familiar "Rock, Paper, Scissors" game! The rules are quite simple and I think everyone understands. Today your opponent will be a computer.')

print('Here we go! If you want to choose a stone, enter the letter "1", for scissors and paper "2" and "3" respectively.')

comp = random.choice(knb)

user = input('Please choose. Stone, scissors or paper? ')

while True:
    if comp == "stone" and user == 1:
        print(f"Tie! The computer picked {comp}")
        break

    elif comp == "scissors" and user == 2:
        print(f"Tie! The computer picked {comp}")
        break

    elif comp == "paper" and user == 3:
        print(f"Tie! The computer picked {comp}")
        break

while True:
    if comp == "stone" and user == 3:
        print(f"You win! The computer has chosen {comp}")
        break

    elif comp == "scissors" and user == 1:
        print(f"You win! The computer has chosen {comp}")
        break

    elif comp == "paper" and user == 2:
        print(f"You win! The computer has chosen {comp}")
        break
        

while True:
    if comp == "stone" and user == 2:
        print(f"You lose! The computer has chosen {comp}")
        break

    elif comp == "scissors" and user == 3:
        print(f"You lose! The computer has chosen {comp}")
        break

    elif comp == "paper" and user == 1:
        print(f"You lose! The computer has chosen {comp}")
        break

Upvotes: 0

Views: 92

Answers (1)

Black Dust
Black Dust

Reputation: 11

Im a bit late for the answer but if you are still looking for one here it is.

    import random
knb = ["stone", "scissors", "paper"]
comp = random.choice(knb)
user = int(input("Choose stone(1), scissors(2) or paper(3)\n")) #inputs are taken as strings and you are comparing integers so use int()
if (user == 1 and comp == "stone") or (user == 2 and comp == "scissors") or (user == 1 and comp == "paper"):
    print("tie") #This is an example to show if you got a tie
print(comp) #This will show what the comp picked

Upvotes: 1

Related Questions