ID Card in Python

You are in college. Every student in your college has a unique ID on their ID Card. Unique ID contains letters, numbers, and hyphens(-). But now, your college administration wants to modify the unique ID of ID Cards. Modifications required are-

  • All letters should be capitalized.
  • Hyphens should come inside ID after a certain fixed length(starting from the right).
  • Fixed length will be given during input.

For example-
Input:
Enter string: as4-12fgt-5hgJ
Enter length: 3
Output:
AS4-12F-GT5-HGJ

Code for ID Card in Python:

s = input('Enter string: ')
n = int(input('Enter length: '))
new_s = ''
for i in s:
    new_s = new_s+ i.upper()
new_s = new_s.split('-')
new_s = ''.join(new_s)
result = []
for i in range(0, len(new_s), n):
    result.append(new_s[i:i+n])
result=result[::-1]
result='-'.join(result)
result=result[::-1]
result=result.split('-')
new_result = []
for i in result:
    new_result.append(i[::-1])
print('-'.join(new_result))

Output:

Output for ID Card in Python

Also Read:

Share:

Author: Harry

Hello friends, thanks for visiting my website. I am a Python programmer. I, with some other members, write blogs on this website based on Python and Programming. We are still in the growing phase that's why the website design is not so good and there are many other things that need to be corrected in this website but I hope all these things will happen someday. But, till then we will not stop ourselves from uploading more amazing articles. If you want to join us or have any queries, you can mail me at admin@violet-cat-415996.hostingersite.com Thank you