Problem 196414 · easy · Phase 01 Prerequisites & Setup

Reverse the Digits

functions · digits · loops

Write reverse_number(n) that returns the integer whose digits are those of n in reverse order. The sign stays where it is, and leading zeros disappear because the result is an integer.

Examples

Input:  n = 1230
Output: 321

Input:  n = -450
Output: -54

Input:  n = 0
Output: 0

Constraints

  • -10**15 <= n <= 10**15

Goals

  • Build a number digit by digit
  • Preserve the sign and drop leading zeros
Starting Python…