Check String Rotation
Check if one string is rotation of another.
AdvancedPhase 5 - Category 5: Advanced String LogicExample 10 of 14
check-string-rotation.py
1# Take two strings2s1 = input("Enter first string: ")3s2 = input("Enter second string: ")45# Check rotation6if len(s1) == len(s2):7 # Concatenate s1 with itself8 temp = s1 + s19 if s2 in temp:10 print("Rotation")11 else:12 print("Not a rotation")13else:14 print("Not a rotation (different lengths)")
Output
Enter first string: hello Enter second string: lohel Rotation
What's going on
Concatenate string with itself and check substring.
Key Concepts:
Check if lengths equal
Concatenate s1 with itself
Check if s2 is substring
🔗Related Content
- 📖
Phase 5 - Learn Concepts
Review Phase 5 concepts and explanations
- 📝
Phase 5 - Quiz
Test your Phase 5 understanding with quiz questions
- 💻
Phase 5 - All Practice Problems
Explore all practice problems for Phase 5
- 🎓
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- 🧠
Logic Building Overview
Learn about the complete logic building curriculum