I am trying to make a little game for my self. first i have an arrays.
After this i want to play flip coin game with this data after it runs 1,2 or 3 wins. After this code
import random rows = [[20,30,40],[30,40,50],[50,20,30]] #Get number to veribals player1 = rows[0][0] player2 = rows[0][1] player3 = rows[0][2] coin = [1,2] print(player1) print(player2) print(player3) game_on = False total_game = player1 + player2 + player3 while not game_on: flip_coin = random.choice(coin) player1_flip = random.choice(coin) player2_flip = random.choice(coin) player3_flip = random.choice(coin) print(total_game) # Testing Code print(f"Total Game Left {total_game}") print(f"Computer : {flip_coin}") print(f"Player 1 : {player1_flip} Player 2 : {player2_flip} Player 3 : {player3_flip}") print(f"Player 1 Left Points : {player1} Player 2 Points : {player2} Player 3 Points : {player3}") if player1_flip == flip_coin: if player1 == 0: pass else: player1 -= 1 if player2_flip == flip_coin: if player2 == 0: pass else: player2 -= 1 if player3_flip == flip_coin: if player3 == 0: pass else: player3 -= 1 total_game = player1 + player2 + player3 if total_game == 1: game_on = True if player1 == 1: print("Player 1 is Won") elif player2 == 1: print("Player 2 is Won") elif player3 == 1: print("Player 3 is Won")
After this come, how can move next array [30,40,50] and [50,20,30]. After all done, i need get 1. Game Player 1 won, 2. Game player 2 won ect.
How can i do it ?
Advertisement
Answer
You just need to wrap most of your code in a for loop:
import random rows = [[20,30,40],[30,40,50],[50,20,30]] for row in rows #Get number to veribals player1 = row[0] player2 = row[1] player3 = row[2] ... # rest of code indented here like this: coin = [1,2]