How would you write this is a more compact way?if v >= 180:
v = 180
elif v >= 160:
v = 160
elif v >= 140:
v = 140
elif v >= 120:
v = 120
elif v >= 100:
v = 100
elif v >= 80:
v = 80
elif v >= 60:
v = 60
elif v >= 40:
v = 40
elif v >= 20:
v = 20
else:
v = 0
Pic related
fucked up the indentation thanks to the code tags.
all if statements are indented the same.
>>57191644foreach(n; [180, 160, 140, 120, 100, 80, 60, 40, 20]) {
if (v >= n) {
v = n;
break;
}
}
>>57191700
Either thus or a step function OP
max(0, min(180, int(n / 20) * 20))
>>57191644if v >= 180:
v = 180
elif v < 0:
v = 0
else:
v = floor(v / 20) * 20
assuming you're using Python 3's division which doesn't round
v / 20 * 20
>>57191716
this is great
>>57191716
that's pretty neat