LIMITED TIME OFFER: 50% OFF OF PREMIUM WITH OUR ANNUAL PLAN (THAT'S $294 IN SAVINGS).
GET OFFER

Conditional Statements Assessment - Pokemon

Screen Link: https://app.dataquest.io/m/2000313/conditional-statements-assessment/3/question-3

My Code:

top_picks = [
    ['Litten', 'Fire', 'NA', 65.0, 40.0, 60.0, 40.0, 70.0, 2.0,
     'Torracat', 'Fire', 'NA', 'Training', 17.0, 85.0, 50.0, 80.0, 50.0, 90.0,
     'Incineroar', 'Fire', 'Dark', 'Training', 34.0, 115.0, 90.0, 80.0, 90.0, 60.0, 'Alola'],
    ['Totodile', 'Water', 'NA', 65.0, 64.0, 44.0, 48.0, 43.0, 2.0,
     'Crocanaw', 'Water', 'NA', 'Training', 18.0, 80.0, 80.0, 59.0, 63.0, 58.0,
     'Feraligatr', 'Water', 'NA', 'Training', 30.0, 105.0, 100.0, 79.0, 83.0, 78.0, 'Johto']
]

Hi ,
This is my first week into the world of programming and I’m finding this exercise extremely difficult.
Can anyone please help me with understanding the logic behind solving this and an answer that I can refer and learn?

Replace this line with the output/error

It’s ok to take your time and return to these assessments later when you get more and more comfortable with the language. But, since these are assessments it’s not really beneficial to you long-term if you attempt to directly learn from the answer.

So, first aim to break down the problem into its individual parts. You have -

  • A list of lists, top_picks, containing 2 lists.
    • Each list has a set of items/values stored in it.

I think, by now, you would have gotten familiar with a list in a lists of lists being similar to a row and each value in that row corresponding to columns.

Next, in the instructions, you are given information on what index each column corresponds to.

Given all of the above information, you are required to compare the values inside those two lists.

For example, column index 3 in both lists is the attack stat. So, you need to check the value for column index 3 in both lists and compare the two. Based on that comparison you need to

  • store the higher value in the variable name corresponding to that stat, or
  • store the string Equal in that variable name if they are the same

If going through the above, step-by-step, is confusing to you then feel free to ask a question related to that step.

But I would recommend that you go through the lists and conditional statements content again to understand what to do here. They also provide practice problems that you can go through as well to get some more experience before attempting these assessments.

Thanks, I will give this a go!

Hi Robert. Since your question relates to a separate assessment than the one in the original question, please create a separate post for yours.

I’ve just completed this assessment and got the question right, however on further inspection in the answer review section it suggested that I needed to use an “if” statement. However I’m not sure how to apply an “if” statement in this question. Does this section require a for loop as well. Here is the code below which helped obtain the right answer but I felt as though I was doing too much repetition. Any clarification would be greatly appreciated.

top_picks = [
    ['Litten', 'Fire', 'NA', 65.0, 40.0, 60.0, 40.0, 70.0, 2.0,
     'Torracat', 'Fire', 'NA', 'Training', 17.0, 85.0, 50.0, 80.0, 50.0, 90.0,
     'Incineroar', 'Fire', 'Dark', 'Training', 34.0, 115.0, 90.0, 80.0, 90.0, 60.0, 'Alola'],
    ['Totodile', 'Water', 'NA', 65.0, 64.0, 44.0, 48.0, 43.0, 2.0,
     'Crocanaw', 'Water', 'NA', 'Training', 18.0, 80.0, 80.0, 59.0, 63.0, 58.0,
     'Feraligatr', 'Water', 'NA', 'Training', 30.0, 105.0, 100.0, 79.0, 83.0, 78.0, 'Johto']
]

row1 = top_picks[0][0:9]
row2 = top_picks[1][0:9]

top_picks = [row1, row2]

best_atk = (row1[3] > row2[3] and 'Litten') or (row1[3] < row2[3] and 'Totodile') or (row1[3] == row2[3] and 'Equal')
  
best_spd = (row1[7] > row2[7] and 'Litten') or (row1[7] < row2[7] and 'Totodile') or (row1[7] == row2[7] and 'Equal')

best_def = (row1[4] > row2[4] and 'Litten') or (row1[4] < row2[4] and 'Totodile') or (row1[4] == row2[4] and 'Equal')

best_sp_atk = (row1[5] > row2[5] and 'Litten') or (row1[5] < row2[5] and 'Totodile') or (row1[5] == row2[5] and 'Equal')

best_sp_def = (row1[6] > row2[6] and 'Litten') or (row1[6] < row2[6] and 'Totodile') or (row1[6] == row2[6] and 'Equal')

Hi @RobertDelves . Since your question relates to a separate assessment than the one in the original question, please create a separate post for yours.

It’s the same assessment as the original question!?

You have chosen a slightly longer/complicated way to compare the contents of the lists than needed. Do note that I have not checked the validity of your code and whether or not it’s correct.

But, there is nothing too complicated to if statements. If you have two variables a and b, then the logic is quite straightforward -

if a > b:
    do_this_1
else:
   do_this_2

If you want more than one comparison -

if a > b:
    do_this_1
elif a < b:
   do_this_2
else:
    do_this_3

I would recommend going through the content and the practice problems on conditional statements again to familiarize yourself with them better.