Founding Batch Offer · HLD · LLD · System Design at ₹799 until 30 Nov

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.

IntermediatePhase 1 - Level 2: Nested If & Multiple ConditionsExample 8 of 10
check-alphabet-range.py
1# Take character
2ch = input("Enter a character: ").lower()
3
4# Check range
5if 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. 1

    Lowercase the entered response.

  2. 2

    Require alphabetic text before comparing letter bounds.

  3. 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.