Answer to Question #231052 in Python for umesh

Question #231052

Masking - 2

Write a program that reads a single line of input and prints the first two and last two characters of the given input and prints the asterisk character (*) in place of the remaining characters.

Explanation

For example, if the given string is

message, then the first two and last two characters are me, ge. Now replacing all the remaining characters with * will give the output me***ge.


1
Expert's answer
2021-08-30T03:50:14-0400
string = input()
if len(string) > 4:
	length = len(string) - 4
	string = string[:2] + '*'*length + string[len(string)-2:]
print(string)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS