One liner that returns text such as "Under 60" and "Over 100"

PHP

$score = 105;
$score_text = sprintf("%s%d", $score % 10 < 5 ? "over-" : "under", round($score, -1));
echo $score_text;
#Under 110

Python3

# -*- coding: utf-8 -*-
score = 105
score_text = "%s%d" % (("over-", score // 10 * 10) if score % 10 < 5 else ("under", (score // 10 + 1) * 10))
print(score_text)
#Under 110

Recommended Posts

One liner that returns text such as "Under 60" and "Over 100"
Optimization such as interpolation and curve fitting