10.1 - Capital check
Problem
Write a procedure that will accept a single character as a parameter.
It should then tell you if that character is a capital letter.
Example run 1
Enter character: B B is a capital letter.
Example run 2
Enter character: b b is not a capital letter.
| 1 | Check if capital | IN | character |
| OUT |
1.1 if ascii value of character is between 65 to 90 inclusive then
1.2 display character and “is a capital letter.”
1.3 else
1.4 display character and “is not a capital letter.”
1.5 end if
# Main
character = input("Enter character: ")
check_capital(character)
def check_capital(character):
if ord(character) >= 65 and ord(character) <= 90:
print(character, "is a capital letter.")
else:
print(character, "is not a capital letter.")
# Main
character = input("Enter character: ")
check_capital(character)
"""
This program checks if a single character entered by the user
is a capital letter (A–Z) by comparing its ASCII code.
Capital letters are between 65 and 90 in the ASCII table.
"""
def check_capital(character):
# Use ord() to convert the character into its code
# Check if the code is between 65 ("A") and 90 ("Z")
if ord(character) >= 65 and ord(character) <= 90:
print(character, "is a capital letter.")
else:
print(character, "is not a capital letter.")
# Main program starts here
# Ask the user to enter a character
character = input("Enter character: ")
# Call the function to check if it's a capital letter
check_capital(character)
Extension
Update the program to
- Validate the character is a string with a length of 1
- Output if the character is a
- Uppercase
- Lowercase
- Number
- Symbol