Computer Science, asked by donyaahmadi832, 3 months ago

given a string, create a new string made up of its last two letters, reversed and separated by a space

scala

Answers

Answered by Anonymous
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