Solution Exercise 51: Python program to generate lists of all characters from its ascii code

Feb 26, 2023

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

By My Courses

3 thoughts on “Solution Exercise 51: Python program to generate lists of all characters from its ascii code”
1. […] using the (Exercise 51), create a python algorithm as a function that takes as input a string s and which returns the same […]

2. […] (Exercise 51), write a python program as a function which takes a string s as input and returns the same string […]