Reverse a name
name = input("Enter your name: ")
reversed_name = name[::-1] print("Reversed name:", reversed_name) In this program, we first ask the user to enter their name using the `input()` function and store it in the `name` variable. Then, we use string slicing with a negative step (`[::-1]`) to reverse the order of the characters in the name, and store the result in the `reversed_name` variable. Finally, we print the reversed name using the `print()` function.
Comments
Post a Comment