Deviopath › Python

Mask a Card Number

Easy · Strings

A negative slice counts from the end: text[-4:] is the last 4 characters. Multiplying a string repeats it: "*" * 3 is "***".

Write a function mask_card(number) that hides every digit except the last 4, replacing each hidden digit with *. The result has the same length as the input. A number with 4 digits or fewer is returned unchanged.

Next: Minutes to h:mm