so I have to make a rock paper scissors game in my class today and was wondering how to make an if statement based on a list's order than setup a loop for that here is the code
def RockPaperScissorsFunction4(roundnumberforcurrentpairing, mychoices[], opponentchoices[]):
import random
first_random = random.randint(1, 3)
# 1 = rock 2 = paper 3 = scissors
if (roundnumberforcurrentpairing == 1 ):
mynextmove = 1
# mynextmove = opponentchoices[roundnumberforcurrentpairing - 2]
if roundnumberforcurrentpairing < 3:
mynextmove = 1
if opponentchoices[1, 3, 3, 3,]:
if opponentchoices[2, 3, 3, 3,]:
if opponentchoices[3, 3, 3, 3,]:
Sergio Tulentsev
231k43 gold badges380 silver badges372 bronze badges
asked Nov 25, 2021 at 18:31
user17499409user17499409
1 Answer 1
Is that you want to For loop with Array child ? If you want opporentchoice [1,3,3,3] to came out as 1 3 3 3 then compare with first_random
here example :
opponentchoices = [1,3,3,3]
for x in opponentchoices:
first_random = random.randint(1, 3)
if(first_random > x):
print("You win")
else:
print("Opporent win")
Anyway you need to us more detail in this question
update
import random
def RockPaperScissorsFunction4(totalround, MyChoices, opponentchoices):
RoundCount = 2
MaxRound = len(opponentchoices) # We do this because we Don't need Max round more than opponent's choice
if(totalround > MaxRound): # if total round is more than choice Set total round = length of opponent's Array
totalround = MaxRound
print("Set totalround = ",totalround)
for opponent_answer in opponentchoices:
if RoundCount >= totalround:
break
if opponent_answer > opponent_answer:
print("opponent win!")
else :
print("Player win!")
RoundCount = RoundCount + 1
player_answer = random.randint(1, 3)
opponent_array = [1, 3, 3, 3]
RockPaperScissorsFunction4(5,player_answer,opponent_array)
player_answer = random.randint(1, 3)
opponent_array = [2, 3, 3, 3]
RockPaperScissorsFunction4(5,player_answer,opponent_array)
player_answer = random.randint(1, 3)
opponent_array = [3, 3, 3, 3]
RockPaperScissorsFunction4(5,player_answer,opponent_array)
answered Nov 25, 2021 at 19:24
lang-py
if opponentchoices[:4] == [1,3,3,3]:
etc.