Newer
Older
bth_py_exercises / 1.7 / swap_units_and_tens.py
@Pascal Syma Pascal Syma on 31 Aug 2021 406 bytes Completed 1.7
"""
Exercise 1.7 - Swap Units and tens
"""


#  Copyright (c) 2021. Pascal Syma. All rights reserved.

def swap_units_and_tens(num: int) -> int:
    """
    Swap the last with the second last digit.

    :return: Swapped number
    :param num: Input number
    """
    string = str(num)

    return int(string[:-2] + string[:-3:-1])


if __name__ == '__main__':
    print(f'{swap_units_and_tens(123) = }')