Sem-2 Practical Practice Question2

Write a python program that performs the following:
Ex. Inputted String : Hello Technocrates
(1) Print all characters by skipping 1 character (Output: HloTcncae)
(2) Print entire string reverse (Output: setarconhceT olleH)
(3) Print length of the String (Output: 18)

Solution.

# Input
input_str = input("Enter a string: ")

# (1) Print all characters by skipping 1 character
skipped_str = input_str[::2]
print("(1) Skipping every second character:", skipped_str)

# (2) Print entire string in reverse
reversed_str = input_str[::-1]
print("(2) Reversed string:", reversed_str)

# (3) Print length of the string
length = len(input_str)
print("(3) Length of the string:", length)

Leave a Reply

Your email address will not be published. Required fields are marked *