I make a scissor toy for stone paper and ran into a decisioncycle() problem. What I'm trying to do is ask the user to enter a choice in usercycle() , make the computer generate a random selection in gamecycle() , and then determine who won the round and track each result with the calculation of gain and loss. It seems to be a solution when need to work at random.
import random class rpsgame: rps= ["rock", "paper","scissors"] wincount=0 losecount=0 def usercycle(self): userchoice = input("rock, paper, scissor.....") print("SHOOT") return userchoice def gamecycle(self): computerchoice = random.choice(rpsgame.rps) return computerchoice def decisioncycle(self): if rpsgame.usercycle(self) == rpsgame.rps[0] and rpsgame.gamecycle(self) == rpsgame.rps[1]: print("paper beats rock, you lose!") rpsgame.losecount +=1 elif rpsgame.usercycle(self) == rpsgame.rps[1] and rpsgame.gamecycle(self) == rpsgame.rps[0]: print("paper beats rock, you win!") rpsgame.wincount+=1 elif rpsgame.usercycle(self) == rpsgame.rps[0] and rpsgame.gamecycle(self) == rpsgame.rps[2]: print("rock beats scissors, you win!") rpsgame.wincount+=1 elif rpsgame.usercycle(self) == rpsgame.rps[2] and rpsgame.gamecycle(self) == rpsgame.rps[0]: print("rock beats scissors, you lose!") rpsgame.losecount+=1 elif rpsgame.usercycle(self) == rpsgame.rps[1] and rpsgame.gamecycle(self) == rpsgame.rps[2]: print("scissors beats paper, you lose!") rpsgame.losecount+=1 elif rpsgame.usercycle(self) == rpsgame.rps[2] and rpsgame.gamecycle(self) == rpsgame.rps[1]: print("scissors beats paper, you win!") rpsgame.wincount+=1 elif rpsgame.usercycle(self) == rpsgame.gamecycle(self): print("it a tie!!!") print("wins {}, losses {}".format(rpsgame.wincount, rpsgame.losecount)) while True: rg = rpsgame() rg.usercycle() rg.gamecycle() rg.decisioncycle()
I think my problem is making a decision (). this is my first shot in class since the game works with global variables, but I read here that this is bad practice for the future.
source share