Uppercase Conversion Recursively
Convert string to uppercase recursively.
AdvancedPhase 3 - Level 4: String-based RecursionExample 8 of 10
uppercase-conversion-recursively.py
1def to_upper(s, index=0):2 # Base case3 if index >= len(s):4 return ""56 # Convert current character7 char = s[index].upper()8 # Recurse9 return char + to_upper(s, index + 1)1011# Test12text = input("Enter a string: ")13result = to_upper(text)14print(f"Uppercase: {result}")
Output
Enter a string: Hello Uppercase: HELLO
What's going on
Convert each character to uppercase.
Key Concepts:
Base case: index >= len(s)
Convert current char to uppercase
Concatenate and recurse
🔗Related Content
- 📖
Phase 3 - Learn Concepts
Review Phase 3 concepts and explanations
- 📝
Phase 3 - Quiz
Test your Phase 3 understanding with quiz questions
- 💻
Phase 3 - All Practice Problems
Explore all practice problems for Phase 3
- 🎓
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- 🧠
Logic Building Overview
Learn about the complete logic building curriculum