Write a Python function to reverse a string without using any built-in functions or slicing.
def reverse_string(input_string):
reversed_string = ""
for i in range(len(input_string) - 1, -1, -1):
reversed_string += input_string[i]
return reversed_string
# Test the function
my_string = "Hello, World!"
reversed = reverse_string(my_string)
print(reversed) #output !dlroW ,olleH
Comments
Post a Comment