Character Loop - Python Programming Exercise

This Python program uses a "for" loop to print the uppercase letters from "B" to "N". By utilizing Python's range() function and specifying the ASCII values of the starting and ending characters, the program iterates through the letters in the specified range. Each letter is printed on the same line to achieve the desired output. This exercise helps improve your understanding of loops and character manipulation in Python, making it an excellent way to practice for loops and ASCII value operations. The for loop is an essential control structure in Python, and learning how to use it for tasks like printing a sequence of characters enhances your ability to automate repetitive tasks efficiently. In this case, the program demonstrates the flexibility of the range() function to generate a sequence of numbers, which can be mapped to corresponding letters using the chr() function, expanding your knowledge of Python’s built-in functions for string and loop operations.

 Category

Python Data Types

 Exercise

Character Loop

 Objective

Develop a Python program to print the letters "B" to "N" (uppercase), using a "for" loop.

 Example Python Exercise

 Copy Python Code
# Loop through the letters from 'B' to 'N' (inclusive)
for letter in range(ord('B'), ord('N') + 1):
    print(chr(letter))

 Output

B
C
D
E
F
G
H
I
J
K
L
M
N

 Share this Python Exercise

 More Python Programming Exercises of Python Data Types

Explore our set of Python Programming Exercises! Specifically designed for beginners, these exercises will help you develop a solid understanding of the basics of Python. From variables and data types to control structures and simple functions, each exercise is crafted to challenge you incrementally as you build confidence in coding in Python.

  •  Double Precision Pi Approximation

    This Python program calculates an approximation for PI using the series expression: pi/4 = 1/1 - 1/3 + 1/5 - 1/7 + 1/9 - 1/11 + 1/13 ... The program allows t...

  •  Perimeter and Area

    This Python program calculates the perimeter, area, and diagonal of a rectangle based on its width and height. The program prompts ...

  •  Hex and Bin

    This Python program prompts the user to enter a number and then displays its equivalent values in both hexadecimal and binary formats. The program conti...

  •  Binary Code

    This Python program prompts the user to enter a decimal number and displays its equivalent in binary form. Instead of using the str() function, the prog...

  •  Conditional Logic and Booleans

    This Python program uses the conditional operator to assign a boolean variable named "bothEven" the value "True" if both numbers entered by the user are...

  •  Exception Handling V2

    This Python program prompts the user for a real number and displays its square root. The program uses a "try...except" block to handle any potential err...