+ 1
How can i make this code better? I want to avoid repetition
if trn == 0: if L == "A": A[N] = "X" elif L == "B": B[N] = "X" elif L == "C": C[N] = "X" elif trn == 1: if L == "A": A[N] = "O" elif L == "B": B[N] = "O" elif L == "C": C[N] = "O"
3 odpowiedzi
+ 2
Use a dictionary. Or two. However. Keys could be either "0A" ff. within a single dictionary or "A", "B" ff. within two dictionaries. For two it's little more logic to access the right one. Edit: Or two dictionaries within a list...
dict["0A"] or dict0["A"] or arr[0]["A"] -> arr = [ {"A" : "test"} ]; print(arr[0]["A"]);
+ 1
This is no code-related but a quiz-question or what? From code perspective I don't care how useless the cases are...
0
I have changed the code, are there any more ways to improve this?
S = "E"
if trn == 0:
S = "X"
elif trn == 1:
S = "O"
if L == "A":
A[N] = S
elif L == "B":
B[N] = S
elif L == "C":
C[N] = S