I'm currently having an issue in my code, in which I am attempting to create a rock paper scissors game. My counting method does not seem to work (when the program looped the win loss counters are both on 0), so I was hoping I could get some help. I am fairly new to Python and stack overflow, so bear that in mind. Sorry for the long wall of code:
import random
import time
win=0
loss=0
def compare():
if choice == "rock" and opp == "paper":
print("You lose!")
loss+1
elif choice == "paper" and opp == "scissors":
print("You lose!")
loss+1
elif choice== "scissors" and opp == "rock":
print("you lose")
loss+1
elif choice == "scissors" and opp == "paper":
print("you win")
win+1
elif choice == "rock" and opp =="scissors":
print("you win")
win+1
elif choice == "paper" and opp == "rock":
print("you win!")
win+1
else:
print("...")
op=["rock","paper","scissors"]
phrase=["Rock paper scissors shoot!","janken bo!", "pierre-feuille-ciseaux!","papier, kamień, nożyczki!"]
while True:
print ("You have",win,"wins and",loss,"losses")
choice=input(random.choice(phrase)).lower()
if choice not in op:
print("Rock paper or scissors")
continue
else:
print()
opp=random.choice(op)
print (opp)
compare()
while opp==choice:
choice=input(random.choice(phrase)).lower()
time.sleep(1)
opp=random.choice(op)
print (opp)
compare()
I appreciate any help. Thanks
win + 1- I suspect you meanwin = win + 1, orwin += 1in short.global winandglobal lossinsidecompareif you're going to assign to them inside the function.