(Display the ASCII character table) Write a program that displays the characters in the ASCII character table from ! to ~. Display ten characters per line. The characters are separated by exactly one space.
Program code:
# Define the starting and ending ASCII values for the characters
start = ord('!') # ASCII value of '!'
end = ord('~') # ASCII value of '~'
# Initialize a counter to keep track of the number of characters displayed
count = 0
# Iterate over the ASCII range from start to end (inclusive)
for ascii_value in range(start, end + 1):
# Convert the ASCII value back to a character
character = chr(ascii_value)
# Print the character with a space, end=' ' ensures they are separated by exactly one space
print(character, end=' ')
# Increment the count
count += 1
# Check if ten characters have been displayed
if count % 10 == 0:
print() # Print a new line after every ten characters
# Print a new line if the last line doesn't have ten characters
if count % 10 != 0:
print()
Executed Output:
! " # $ % & ' ( ) *
+ , - . / 0 1 2 3 4
5 6 7 8 9 : ; < = >
? @ 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 [ \
] ^ _ ` 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
{ | } ~