Difficulty reassigning lists to variables during control flow

I am currently building a piece code that will select elements from a list (“deck”) in consecutive groups of 3 and assign them to variables. I want the new sample lists of three to be assigned to the variable “spr” based on user input. However, the control flow does not seem to be operating. Here is a brief example:

deck = list(range(54)) a = deck[0:3] b = deck[3:6] c = deck[6:9] d = deck[9:12] e = deck[12:15] f = deck[15:18] g = deck[18:21] h = deck[21:24] i = deck[24:27] j = deck[27:30] k = deck[30:33] l = deck[33:36] m = deck[36:39] n = deck[39:42] o = deck[42:45] p = deck[45:48] q = deck[48:51] r = deck[50:53] spr = list(range(3)) i = 'c' if i == 'a' or 'A': spr = a elif i == 'b' or 'B': spr = b elif i == 'c' or 'C': spr = c print(c) elif i == 'd' or 'D': spr = d elif i == 'e' or 'E': spr = e elif i == 'f' or 'F': spr = f elif i == 'g' or 'G': spr = g elif i == 'h' or 'H': spr = h elif i == 'i' or 'I': spr = i elif i == 'j' or 'J': spr = j elif i == 'k' or 'k': spr = k elif i == 'l' or 'L': spr = l elif i == 'm' or 'M': spr = m elif i == 'n' or 'N': spr = n elif i == 'o' or 'O': spr = o elif i == 'p' or 'P': spr = p elif i == 'q' or 'Q': spr = q elif i == 'r' or 'R': spr = r else: print("error") print(spr)

If i == ‘c’, the output of this code will be:

Choose a letter A - R: c
[0, 1, 2]

I am assuming that the control flow is being ignored, as the “print(c)” function is not being run when the user inputs “c”.

I did not run into this problem during the Magic 8 Ball project. Is it because it’s the first time I’m using lists?

What am I missing?

This is also my first project using lists

It’s your if statements that are giving you the issue. For instance;
if i == ‘a’ or ‘A’:
works out to;
if i == ‘a’
if ‘A’
i.e. it’s not comparing ‘A’ to i, but just querying whether it’s a truthy value. And because it is, your code isn’t stopping at the first if.
You could change it to;
if i == ‘a’ or i == ‘A’:
so it would check both cases, or you could have something like;
i = i.lower()
so i is set to lowercase and you only need to check one thing.

Hope that helps

1 Like