Python Program to Print N Letters of Alphabets in Lowercase

In this article, we will learn about python program to print n letters of alphabets in lowercase.

Getting Started

We have already covered how to print n letters of alphabets of uppercase. Now, we will learn to do same task in lowercase.

If N = 3, output is –

a b c

If N = 2, output is –

a b

Above task can be achieved in many ways –

Print N Letters of Alphabets in Lowercase Using For Loop

Python Program to print N letters of alphabets in lowercase using for loop –

n = int(input("Enter number of letters to print"))
for i in range(n):
    print(chr(97 + i), end = " ")

Output:

Enter number of letters to print
5
a b c d e 

97 is ASCII value of a. chr() returns character corresponding to given integer value.

Print N Letters of Alphabets in Uppercase Using While Loop

Pseudo Algorithm

  • Initialise variable i with 0
  • Check if value of i is less than n or not inside while loop.
  • If yes, print character using ascii value. 97 is ASCII value of a. So, 97 + i will be ASCII value of subsequent letters.
  • After printing value, increment value of i by 1.

Print n letters of alphabets in lowercase using while loop –

n = int(input("Enter number of letters to print"))
i = 0
while (i < n):
    print(chr(97 + i), end = " ")
    i = i + 1

Output:

Enter number of letters to print
10
a b c d e f g h i j

Print N Letters of Alphabet Using String Constant – ascii_lowercase

Using string constant ascii_lowercase, we can retrieve alphabets in lowercase.

import string
n = int (input("Enter number of letters to print"))
res = string.ascii_lowercase[:n]
print(str(res))

Output:

Enter number of letters to print
16
abcdefghijklmnop

ascii_lowercase returns alphabets in lowercase up-to given count.

Reference: Official Doc

Leave a Reply