Python Program
Write a python program to print the following output.
Input
The first line contains a string S representing a unique id.
The second line contains an integer N representing group length.
Output
The output should be a single string representing the new unique id.
Sample Input1
2-4A0r7-4k
3
Sample Output1
24-A0R-74K
def adding_separator(input_str, group_len):
for i in range(0, len(input_str), group_len):
yield input_str[i:i+group_len]
while True:
try:
S=str(input('Enter id: '))
break
except:
print ('You can only enter string.')
while True:
try:
N=int(input('Enter group length: '))
break
except:
print ('You can only enter integer.')
res_S=S.strip().replace('-','')
rev_S=res_S[::-1].upper()
new_id= '-'.join(adding_separator(rev_S, N))[::-1]
print (new_id)
Comments
Leave a comment