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:
Also Read:
- Hyphenate Letters in Python
- Earthquake in Python | Easy Calculation
- Striped Rectangle in Python
- Perpendicular Words in Python
- Free shipping in Python
- Raj has ordered two electronic items Python | Assignment Expert
- Team Points in Python
- Ticket selling in Cricket Stadium using Python | Assignment Expert
- Split the sentence in Python
- String Slicing in JavaScript
- First and Last Digits in Python | Assignment Expert
- List Indexing in Python
- Date Format in Python | Assignment Expert
- New Year Countdown in Python
- Add Two Polynomials in Python
- Sum of even numbers in Python | Assignment Expert
- Evens and Odds in Python
- A Game of Letters in Python
- Sum of non-primes in Python
- Smallest Missing Number in Python
- String Rotation in Python
- Secret Message in Python
- Word Mix in Python
- Single Digit Number in Python
- Shift Numbers in Python | Assignment Expert
- Weekend in Python
- Shift Numbers in Python | Assignment Expert
- Temperature Conversion in Python
- Special Characters in Python
- Sum of Prime Numbers in the Input in Python