Character Pattern
Print character pattern: A, AB, ABC, ...
IntermediatePhase 2 - Level 4: Pattern PrintingExample 6 of 13
character-pattern.py
1# Take n2n = int(input("Enter number of rows: "))34# Print pattern5for i in range(1, n + 1):6 for j in range(i):7 print(chr(65 + j), end="") # 65 is ASCII of 'A'8 print()
Output
Enter number of rows: 4 A AB ABC ABCD
What's going on
Print characters using ASCII values.
Key Concepts:
chr(65) = 'A', chr(66) = 'B', etc.
Print characters from A to A+i-1
Use chr() function
🔗Related Content
- 📖
Phase 2 - Learn Concepts
Review Phase 2 concepts and explanations
- 📝
Phase 2 - Quiz
Test your Phase 2 understanding with quiz questions
- 💻
Phase 2 - All Practice Problems
Explore all practice problems for Phase 2
- 🎓
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- 🧠
Logic Building Overview
Learn about the complete logic building curriculum