Check Alphabet Range
Place a letter in the a-to-m or n-to-z range using Python. Students explore nested checks, lowercasing, and the difference between Unicode letters and ASCII.
1# Take character2ch = input("Enter a character: ").lower()34# Check range5if ch.isalpha():6 if 'a' <= ch <= 'm':7 print("Character is between 'a' and 'm'")8 elif 'n' <= ch <= 'z':9 print("Character is between 'n' and 'z'")10else:11 print("Not an alphabet")
Output
Enter a character: f Character is between 'a' and 'm' Enter a character: t Character is between 'n' and 'z'
In this one
- Normalize letter case
- Nest a range decision
- Distinguish ASCII from Unicode
How it works
- 1
Lowercase the entered response.
- 2
Require alphabetic text before comparing letter bounds.
- 3
Print the matching English range when present.
Edge cases
What happens for F?
What happens for F?
It becomes f and prints the a-to-m message.
Does é receive a range label?
Does é receive a range label?
No. It is alphabetic but outside both ASCII letter ranges in this code.
What's going on
lower makes an uppercase English letter comparable with the lowercase bounds. isalpha is the outer guard; the two inner comparisons split the English alphabet into two ranges.
Input f belongs to the first range and t to the second. String comparisons use character ordering rather than dictionary meaning. The guard accepts more than English letters, so some alphabetic Unicode input can pass isalpha but match neither inner range.
What happens for F? It becomes f and prints the a-to-m message.
Does é receive a range label? No. It is alphabetic but outside both ASCII letter ranges in this code.
Quiz
Tap an option. The answer stays hidden until you pick.
Question 1
What does lower do before testing?
Pick an answer to check it.
Question 2
What happens for F?
Pick an answer to check it.
Questions people ask
What happens for F?
It becomes f and prints the a-to-m message.
Does é receive a range label?
No. It is alphabetic but outside both ASCII letter ranges in this code.
What does lower do before testing?
Normalizes uppercase English letters.
🔗Related Content
- 📖
Phase 1 - Learn Concepts
Review Phase 1 concepts and explanations
- 📝
Phase 1 - Quiz
Test your Phase 1 understanding with quiz questions
- 💻
Phase 1 - All Practice Problems
Explore all practice problems for Phase 1
- 🎓
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- 🧠
Logic Building Overview
Learn about the complete logic building curriculum