-1

I'm trying to make an easy beggar my neighbour game using Python.

I've two lists named p1 and p2 which both have random elements like ['A', 'K', '9', '2'] etc...

I've also a dictionary named cards_values with keys and values like: {'A': 13, 'K': 12} etc...

...and now I want to compare these two lists using a dictionary to check which player won the round

I'm not gonna paste the code 'cause I want a hint/advice, not the solution.

Sevy
  • 93
  • 10
  • 1
    this seems like a simple task if you understand how to use dicts/lists, where are you stuck? – Chris_Rands Sep 20 '19 at 13:58
  • Hi, welcome to SO. Sadly, we're not here to give you hint/advice, we're here to provide solutions, to code that's not working. Please consider reading [How to ask](https://stackoverflow.com/help/how-to-ask). – tituszban Sep 20 '19 at 13:58

2 Answers2

0

HINT: Look into the **x (2nd) argument of the dict constructor.

Answer: Check out this answer and this answer for the exact solution.

meshtron
  • 1,110
  • 9
  • 19
0

I'm not gonna paste the code 'cause I want a hint/advice, not the solution.

Okay.

So you basically need to get all cards' values for each player, right?

  1. Do you know how to get one card's value?
  2. All cards for one player = p1 or p2. All cards' values for one player = for each card do the thing you did above. And sum it.

Code hints/answers below.


  1. cards_values['A']
  2. For loop:
sum_p1 = 0
for card in p1:
    sum_p1 += cards_values[card]
h4z3
  • 5,265
  • 1
  • 15
  • 29