Reply
Wed 1 Sep, 2021 03:34 pm
I was doing rock,paper,scissors game in python but whenever ı run the code it's going to else situation which is(print("Enter right words.")
How can ı fix it ?
import random
list = ["Rock","Paper","Scissors"]
live = 3
while True:
pc_choice = random.choice(list)
your_choice = input("Rock,Paper or Scissors? ")
if(your_choice.lower()=="Rock" and pc_choice.lower()=="Rock"):
print("DRAW!")
elif(your_choice.lower()=="Rock"and pc_choice.lower()=="Paper"):
live-=1
print("You lost. You have {} live".format(live))
elif (your_choice.lower() == "Rock" and pc_choice.lower()=="Scissors"):
print("You win.")
elif(your_choice.lower()=="Paper"and pc_choice.lower()=="Rock"):
print("You win")
elif (your_choice.lower() == "Paper" and pc_choice.lower()=="Paper"):
print("DRAW!")
elif (your_choice.lower() == "Paper" and pc_choice.lower()=="Scissors"):
live-=1
print("You lost.You have {} live".format(live))
elif(your_choice.lower()=="Scissors" and pc_choice.lower()=="Rock"):
live-=1
print("You lost. You have {} live".format(live))
elif (your_choice.lower() == "Scissors" and pc_choice.lower()=="Paper"):
print("You win")
elif (your_choice.lower() == "Scissors" and pc_choice.lower()=="Scissors"):
print("DRAW!")
if(live==0):
print("You have none live you lost.")
break
else:
print("Enter right words.")
@mesutanlak,
For one thing... your_choice.lower() always returns lower case. Comparing it to "Rock" (which has an upper case letter) will always return false.
Try changing this to your_choice.lower == "rock".