2

So let's say I have a list

answer_list = aaAbaBabBaBBaAbBAb

What am trying to do is something like this

dimension_1_index = 0
dimension_1_b_answers = 0

while dimension_1_index <= len(answer_list):
    if answer_list[dimension_1_index] == "b" or "B":
        dimension_1_b_answers += 1
        dimension_1_index += 7
    else:
        continue

print(dimension_1_b_answers)

so I'm trying to check for every 7 characters, if the character is either a lowercase or uppercase B, I increment dimension_1_b_answers. But when I run the program, I get no result.

Mina Messiah
  • 119
  • 6
  • The program is running, but since you're not printing anything you won't see any output. – dmlittle Oct 05 '16 at 05:26
  • I actually have a print statement that I forgot to add. Thanks for pointing it out! – Mina Messiah Oct 05 '16 at 05:31
  • I know this was marked as a duplicate but your code additionally needs some work and your comparison is wonky, because `or "B"` is always going to return a truthy value, it's not doing the comparison you believe it to be. I had an answer but couldn't get it in before the question was locked down preventing me from adding an answer. – Mike McMahon Oct 05 '16 at 05:37
  • @MikeMcMahon lol can you share it in the comments ? – Mina Messiah Oct 05 '16 at 05:43
  • update your if to `answer_list[dimension_1_index] in "bB"` then remove the else statement and add an increment to your while statement to move the index by 1 `dimension_1_index += 1` you don't need the continue statement and if you never increment the index you'll be stuck comparing that index to infinity if the first value is never a 'b' or 'B'. Finally if you are only interested in every 7th index you could do a simple `for val in answer_list[7::7]` which will increment by 7 each iteration. HOWEVER note, that doing so will miss a lot of `b`s in your answer list. – Mike McMahon Oct 05 '16 at 05:47
  • @MikeMcMahon Thanks ! I'm still kinda stuck hough. Do I still have to increment the 'dimension_1_index += 1' even if I want it every 7 indexes? am also unsure on how to write the 'for val in answer_list[7::7]'. I emailed you, if you can reply to my email I think would be easier. Thanks again! – Mina Messiah Oct 05 '16 at 05:56

0 Answers0