Toggle Case
Toggle case of each character.
IntermediatePhase 5 - Category 2: Character OperationsExample 8 of 10
toggle-case.py
1# Take string input2s = input("Enter a string: ")34# Toggle case5result = ""6for char in s:7 if char.isupper():8 result += char.lower()9 elif char.islower():10 result += char.upper()11 else:12 result += char1314print(f"Toggled: {result}")
Output
Enter a string: Hello Toggled: hELLO
What's going on
Convert uppercase to lowercase and vice versa.
Key Concepts:
Check if uppercase or lowercase
Convert accordingly
Keep other characters as is
🔗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