Print out all beginner repeat cards

Asked 2 years ago, Updated 2 years ago, 65 views

Hello, I'm a student who just learned coding. I have to print out the results below, but it's not as easy as I thought.


symbol_list = ['Spade','Heart','Diamond','Clover']

for i in range(1,53):
  for j in symbol_list:
    for k in "A",'2','3','4','5','6','6','7','8','9','10','J','Q','K':
      print(i, j,k)


I worked really hard on this. I'm writing to get some advice on the approach. Help me.

loops for python

2022-09-20 19:11

1 Answers

Please keep that in mind.

symbol_list = ['Spade','Heart','Diamond','Clover']
card_rank = list('A') + list(range(2, 11)) + list('JQK')

import itertools as it

card_combi = it.product(symbol_list, card_rank)
for index, pair in enumerate(card_combi, start=1):
    print(f'{index} {pair[0]} {pair[1]}')

1 Spade A
2 Spade 2
3 Spade 3
4 Spade 4
5 Spade 5
6 Spade 6
7 Spade 7
8 Spade 8
9 Spade 9
10 Spade 10
11 Spade J
12 Spade Q
13 Spade K
14 Heart A
15 Heart 2
16 Heart 3
17 Heart 4
18 Heart 5
19 Heart 6
20 Heart 7
21 Heart 8
22 Heart 9
23 Heart 10
24 Heart J
25 Heart Q
26 Heart K
27 Diamond A
28 Diamond 2
29 Diamond 3
30 Diamond 4
31 Diamond 5
32 Diamond 6
33 Diamond 7
34 Diamond 8
35 Diamond 9
36 Diamond 10
37 Diamond J
38 Diamond Q
39 Diamond K
40 Clover A
41 Clover 2
42 Clover 3
43 Clover 4
44 Clover 5
45 Clover 6
46 Clover 7
47 Clover 8
48 Clover 9
49 Clover 10
50 Clover J
51 Clover Q
52 Clover K


2022-09-20 19:11

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.