-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.

2
  • 1
    this seems like a simple task if you understand how to use dicts/lists, where are you stuck? Commented Sep 20, 2019 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. Commented Sep 20, 2019 at 13:58

2 Answers 2

0

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

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

Sign up to request clarification or add additional context in comments.

Comments

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]

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.