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
JavaScript
x
63
63
1
import random
2
rows = [[20,30,40],[30,40,50],[50,20,30]]
3
4
#Get number to veribals
5
player1 = rows[0][0]
6
player2 = rows[0][1]
7
player3 = rows[0][2]
8
9
coin = [1,2]
10
11
print(player1)
12
print(player2)
13
print(player3)
14
15
game_on = False
16
total_game = player1 + player2 + player3
17
while not game_on:
18
19
flip_coin = random.choice(coin)
20
player1_flip = random.choice(coin)
21
player2_flip = random.choice(coin)
22
player3_flip = random.choice(coin)
23
24
print(total_game)
25
26
# Testing Code
27
print(f"Total Game Left {total_game}")
28
print(f"Computer : {flip_coin}")
29
print(f"Player 1 : {player1_flip} Player 2 : {player2_flip} Player 3 : {player3_flip}")
30
print(f"Player 1 Left Points : {player1} Player 2 Points : {player2} Player 3 Points : {player3}")
31
32
if player1_flip == flip_coin:
33
if player1 == 0:
34
pass
35
else:
36
player1 -= 1
37
if player2_flip == flip_coin:
38
if player2 == 0:
39
pass
40
else:
41
player2 -= 1
42
if player3_flip == flip_coin:
43
if player3 == 0:
44
pass
45
else:
46
player3 -= 1
47
total_game = player1 + player2 + player3
48
if total_game == 1:
49
game_on = True
50
51
52
53
54
55
56
if player1 == 1:
57
print("Player 1 is Won")
58
elif player2 == 1:
59
print("Player 2 is Won")
60
elif player3 == 1:
61
print("Player 3 is Won")
62
63
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:
JavaScript
1
13
13
1
import random
2
rows = [[20,30,40],[30,40,50],[50,20,30]]
3
4
for row in rows
5
#Get number to veribals
6
player1 = row[0]
7
player2 = row[1]
8
player3 = row[2]
9
10
11
# rest of code indented here like this:
12
coin = [1,2]
13