LoginSignup
0
0

More than 5 years have passed since last update.

「アンダー60」「オーバー100」とかのテキストを返すワンライナー

Posted at

PHP

$score = 105;
$score_text = sprintf("%s%d", $score % 10 < 5 ? "オーバー" : "アンダー", round($score, -1));
echo $score_text;
# アンダー110

Python3

# -*- coding: utf-8 -*-
score = 105
score_text = "%s%d" % (("オーバー", score // 10 * 10) if score % 10 < 5 else ("アンダー", (score // 10 + 1) * 10))
print(score_text)
# アンダー110
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0