given a string, create a new string made up of its last two letters, reversed and separated by a space
scala
Answers
Answered by
0
Answer:
print("Enter a string:")
a_string = input()
len_of_a = len(a_string)
new_char_1 = a_string[len_of_a-2]
new_char_2 = a_string[len_of_a-1]
new_string = new_char_2+" "+new_char_1
print("Reverse of last 2 letters by adding space in between them:")
print(new_string)
Explanation:
1. take the string
2. get the string length
3. split the last 2 letters of that string
4. store them in 2 variables
5. create new_string and concatenate those 2 string in reverse and by adding a space between them
Output:
Enter a string:
Reverse of last 2 letters by adding space in between them:
Explanation:
Similar questions
Math,
1 month ago
Social Sciences,
1 month ago
Math,
3 months ago
Hindi,
3 months ago
Social Sciences,
9 months ago