Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Python
print("Let's play Stone(1), Paper(2), Sissors(3)")
import random
no=random.randint(1,3)
if no==1:
    computer="stone"
elif no==2:
    computer="paper"
elif no==3:
    computer="sissors"
print(computer)
pla=int(input("It's your chance|1 for Stone| 2 for Paper| 3 for Sissors|:\n"))
print(computer)
if pla==1:
    player="Stone"
elif pla==2:
    player="Paper"

elif pla==3:
    player="Sissors"
else:
    pass
if player==1 or computer==2:
    print("Computer:Paper\n Player:Stone \n Computer wins!")

elif player==1 and computer==3:
    print("Computer:sissors\n Player:Stone \n Player wins!")

elif player==1 and computer==1:
    print("Computer:Stone\n Player:Stone \n Draw!")

elif player==2 and computer==1:
    print("Computer:Stone\n Player:Paper \n Player Wins!")

elif player==2 and computer==3:
    print("Computer:Sissors\n Player:Paper \n Computer Wins!")

elif player==2 and computer==2:
    print("Computer:Paper\n Player:Paper \n Draw!")

elif player==3 and computer==2:
    print("Computer:Paper\n Player:Sissors \n Player wins!")

elif player==3 and computer==1:
    print("Computer:Stone\n Player:Sissors \n Computer wins!")

elif player==3 and computer==3:
    print("Computer:Sissors\n Player:Sissors \n Draw!")


What I have tried:

I have written 'print(computer)' to check if the randomizer is working or not.
Posted
Updated 17-Jul-22 6:40am
v2
Comments
0x01AA 17-Jul-22 6:03am    
Your evaluation is implemented using the numbers 1,2,3. But 'player' and 'computer' do hold the values Stone,Paper,Sissors.
You should use 'no' and 'pla' for the evaluation
Akshat Parmar 17-Jul-22 6:08am    
this program stops after I enter my input and does not work after"print(computer)".
0x01AA 17-Jul-22 6:17am    
No it does not stop, it simply finds no result because you compare e.g. if player==1 or computer==2: and player and computer do hold values like 'Paper', 'Stone', 'Sissors' and not the number 1, 2 or 3.
That means use e.g. if pla==1 or no==2: and so on the evaluation of the result.

[Edit]
I suggest to add that after the last elif:
else:
    print("Smoething went wrong")
Akshat Parmar 17-Jul-22 6:27am    
thanks, it worked!!
0x01AA 17-Jul-22 6:32am    
You are welcome. I added it as a 'solution 2' I suggest also to go through 'Solution 1' as a next learning step ;)

Try this, and look carefully at the differences between player and pla, and computer and comp. Also the first if statement should use the and operator, not or.
Python
print("Let's play Stone(1), Paper(2), Sissors(3)")
import random
computer=random.randint(1,3)
# computer is a number, comp is a string
if computer==1:
    comp="stone"
elif computer==2:
    comp="paper"
elif computer==3:
    comp="sissors"
print(comp)
player=int(input("It's your chance|1 for Stone| 2 for Paper| 3 for Sissors|:\n"))
if player==1:
    pla="Stone"
elif player==2:
    pla="Paper"

elif player==3:
    pla="Sissors"
else:
    pass
print(pla)
# player is a number, pla is a string
if player==1 and computer==2:
    print("Computer:Paper\n Player:Stone \n Computer wins!")

elif player==1 and computer==3:
    print("Computer:sissors\n Player:Stone \n Player wins!")

elif player==1 and computer==1:
    print("Computer:Stone\n Player:Stone \n Draw!")

elif player==2 and computer==1:
    print("Computer:Stone\n Player:Paper \n Player Wins!")

elif player==2 and computer==3:
    print("Computer:Sissors\n Player:Paper \n Computer Wins!")

elif player==2 and computer==2:
    print("Computer:Paper\n Player:Paper \n Draw!")

elif player==3 and computer==2:
    print("Computer:Paper\n Player:Sissors \n Player wins!")

elif player==3 and computer==1:
    print("Computer:Stone\n Player:Sissors \n Computer wins!")

elif player==3 and computer==3:
    print("Computer:Sissors\n Player:Sissors \n Draw!")

This could be simplifies considerably by the use of some of Python's list types, but I leave that as an exercise for you.
 
Share this answer
 
See also the comments to the question.

The problem is, that you evaluate with the variables player and computer (which hold the strings'Paper', 'Stone', 'Sissor') instead of no and pla.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900