Answer to Question #343955 in Python for Kiran

Question #343955

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



1
Expert's answer
2022-05-23T15:18:09-0400
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)

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