0

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 badges381 silver badges373 bronze badges
asked Nov 25, 2021 at 18:31
2
  • If I understand the question properly, I think you can do if opponentchoices[:4] == [1,3,3,3]: etc. Commented Nov 25, 2021 at 18:44
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Commented Nov 30, 2021 at 16:04

1 Answer 1

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.