Answer to Question #335347 in Python for Venkatesh Reddy

Question #335347

ID Card: In Rahul's college, every student is uniquely identified by a string(unique id) which is printed on the ID card of the student.This unique id is comprised if 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 n0.of characters to group (group length),you need to generate the new id.NOTE: While generating the unique id,group the characters from right to left.

INPUT: The first line contains a string S representing a unique id.

Second line contains an integer N representing group length.

OUTPUT: Output should be a single string representing the new unique id.

INPUT:

2-4A0r7-4k

3

OUTPUT:

24-A0R-74K


INPUT:

5F3Z-2e-9-w

4

OUTPUT:

5F3Z-2E9W



1
Expert's answer
2022-04-29T08:21:09-0400
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])

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