Exercise 51

Using ascii code, write a Python program to generate lists of uppercase and lowercase letters: [A, B, C, ..., Z] , [a, b, c,. .., z]

Solution

uppercase = []
lowercase = []

# ASCII codes for uppercase letters are in the range 65 to 90
for i in range(65, 91):
    uppercase.append(chr(i))

# ASCII codes for lowercase letters are in the range 97 to 122
for i in range(97, 123):
    lowercase.append(chr(i))

print("Uppercase letters:", uppercase)
print("Lowercase letters:", lowercase)
"""
Output:
Uppercase letters: ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
Lowercase letters: ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
"""




 

Younes Derfoufi
my-courses.net

3 thoughts on “Solution Exercise 51: Python program to generate lists of all characters from its ascii code”

Leave a Reply