In python how can I shorten the code below?
if x == 15:
y = 0
elif x == 14:
y = 1
elif x == 13:
y = 2
...
...
...
elif x == 0:
y = 15
Currently the solutions I’ve gotten are
y = 15-x
and adding a dictionary.
>Solution :
There Is A Pattern Your Code if x = 15 then y = 0 and if x = 14 then y = 1.
If you just subtract x from 15 then you get the value of y.
There is an equation made (if you know about math):
x+y = 15
then,
y = 15 -x
This Is The Code.
x = #value you use
y = 15 -x