-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcredit_mask.py
32 lines (28 loc) · 1021 Bytes
/
credit_mask.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
'''
Usually when you buy something, you're asked whether your credit card number,
phone number or answer to your most secret question is still correct.
However, since someone could look over your shoulder, you don't want that
shown on your screen. Instead, we mask it.
Your task is to write a function maskify, which changes all but
the last four characters into '#'.
Examples
maskify("4556364607935616") == "############5616"
maskify( "64607935616") == "#######5616"
maskify( "1") == "1"
maskify( "") == ""
# "What was the name of your first pet?"
maskify("Skippy") == "##ippy"
maskify("Nananananananananananananananana Batman!") ==
"####################################man!"
'''
def maskify(cc):
res=""
if len(cc)>4:
for i in range(0,len(cc)-4):
res=res+"#"
for j in range(len(cc)-4, len(cc)):
res=res+cc[j]
return res
else:
return cc
pass