Logic Building
# Take two strings
s1 = input("Enter first string: ")
s2 = input("Enter second string: ")
# Check rotation
if len(s1) == len(s2):
# Concatenate s1 with itself
temp = s1 + s1
if s2 in temp:
print("Rotation")
else:
print("Not a rotation")
else:
print("Not a rotation (different lengths)")Output
Enter first string: hello Enter second string: lohel Rotation
Concatenate string with itself and check substring.
Key Concepts:
- Check if lengths equal
- Concatenate s1 with itself
- Check if s2 is substring