def remove_nth_index_char(input_string, n):
"""
Remove the character at the nth index from the input string.
Args:
input_string (str): The string to process.
n (int): The index of the character to remove.
Returns:
str: A new string with the nth character removed.
"""
if n < 0 or n >= len(input_string):
raise ValueError("Index n is out of range.")
return input_string[:n] + input_string[n+1:]
if __name__ == "__main__":
input_string = input("Enter a non-empty string: ")
try:
n = int(input("Enter the index of the character to remove: "))
result = remove_nth_index_char(input_string, n)
print("String after removing the nth index character:", result)
except ValueError as e:
print("Error:", e)
#source code --> clcoding.com
0 Comments:
Post a Comment