Python programs to display uppercase letters from A to Z or lowercase letters from a to z have been shown here. Both the iterative and recursive approaches have been covered.
1. Python program & output to Display Characters from A to Z
1.1. Python program & output to Display Characters from A to Z using Iteration
# ************************************** # alphabetacoder.com # Python Program to display characters # from A to Z or a to z using iteration # *************************************** # take input of the number print("Enter 1 to display A to Z") print("Enter 2 to display a to z") s = int(input("Your choice >> ")) # display result if s == 1: # display uppercase letters for i in range(ord("A"), ord("Z") + 1): print(chr(i), end=" ") elif s == 2: # display lowercase letters for i in range(ord("a"), ord("z") + 1): print(chr(i), end=" ") else: print("Wrong choice!")
Output
Case 1:
Enter 1 to display A to Z
Enter 2 to display a to z
Your choice >> 1
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
Case 2:
Enter 1 to display A to Z
Enter 2 to display a to z
Your choice >> 2
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
Case 3:
Enter 1 to display A to Z
Enter 2 to display a to z
Your choice >> 3
Wrong choice!
1.2. Python program & output to Display Characters from A to Z using Recursion
# ************************************** # alphabetacoder.com # Python Program to display characters # from A to Z or a to z using recursion # *************************************** # recursive function to print uppercase A to Z def print_uppercase(i, j): # display current character print(chr(i), end=" ") # exit condition if i == j: return # call function i += 1 print_uppercase(i, j) # recursive function to print lowercase a to z def print_lowercase(i, j): # display current character print(chr(i), end=" ") # exit condition if i == j: return # call function i += 1 print_lowercase(i, j) def main(): # take input of the number print("Enter 1 to display A to Z") print("Enter 2 to display a to z") s = int(input("Your choice >> ")) # display result if s == 1: # display uppercase letters # by calling recursive function print_uppercase(ord("A"), ord("Z")) elif s == 2: # display lowercase letters # by calling recursive function print_lowercase(ord("a"), ord("z")) else: print("Wrong choice!") # driver code main()
Output
Case 1:
Enter 1 to display A to Z
Enter 2 to display a to z
Your choice >> 1
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
Case 2:
Enter 1 to display A to Z
Enter 2 to display a to z
Your choice >> 2
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
Case 3:
Enter 1 to display A to Z
Enter 2 to display a to z
Your choice >> 0
Wrong choice!