[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Advertisement | Home]

How would you write this is a more compact way? if v >= 180:

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 9
Thread images: 1

File: stanford.png (231KB, 1000x1000px) Image search: [Google]
stanford.png
231KB, 1000x1000px
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.
>>
>>57191644
foreach(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))
>>
>>57191644
if 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
Thread posts: 9
Thread images: 1


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

If you need a post removed click on it's [Report] button and follow the instruction.
If you like this website please support us by donating with Bitcoin at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties. Posts and uploaded images are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that website. If you need information about a Poster - contact 4chan. This project is not affiliated in any way with 4chan.