In rahul's school every student is uniquely identified by a string which is printed on the id card of the student .This unique id is comprised of letters and digits separated by hyphens into groups of different lengths.The college administration decides to standardize this unique id on the id card by regrouping the letters of the previous unique id to a fixed group length.the college administration also does not want to have lowercase letters in the new id.you need to help the college administration with this task.Given the previous id,and the no.of characters to group,you need to generate the new id
note:while generating the new unique id ,group the characters from right to left
input:the 1st line containing a string S representing a unique id.
the 2nd line containing an integer N representing group length
i/p:2-4A0r7-4k
3
o/p:24-A0R-74K
i/p:
5F3Z-2e-9-w
4
O/P:5F3Z-2E9W
ip = input('i/p:').replace('-', '')
step = int(input())
ip_cap = [i.upper() for i in ip][::-1]
ans = ''
for i in range(1, len(ip_cap) + 1):
if i % step == 0 and ip_cap[i-1] != ip_cap[-1]:
ans += ip_cap[i - 1] + '-'
else:
ans += ip_cap[i - 1]
print(ans[::-1])
i/p:2-4A0r7-4k
3
o/p: 24-A0R-74K
i/p:5F3Z-2e-9-w
4
o/p: 5F3Z-2E9W
Comments
Leave a comment