Contents
- ascii.py
- ascii_table.py
- handling_bad_input.py
ascii.py 1/3
[top][prev][next]
# Conversion of a text message into ASCII
# by Sara Sprenkle
print()
print("This program converts a textual message into a sequence")
print("of numbers representing the ASCII encoding of the message.")
print()
message = input("Enter the message to encode: ")
print()
print("Here are the ASCII codes for '" + message + "':")
for ch in message:
print(ord(ch), end=" ")
print()
ascii_table.py 2/3
[top][prev][next]
# Create a table of numbers (ASCII) and their character equivalent
# by Sara Sprenkle
print("This program prints out the ASCII Table")
print("DEC CHAR")
print("-"*3, "-"*4)
for i in range(33, 127):
print("%3d %4s" % (i, chr(i)))
handling_bad_input.py 3/3
[top][prev][next]
# Handling Bad Input
# by Sara Sprenkle
WMIN = 2
WMAX = 80
HMIN = 2
HMAX = 20
WIDTH_INPUT = "Enter a width (" + str(WMIN) + "-" + str(WMAX) + "): "
HEIGHT_INPUT = "Enter a height (" + str(HMIN) + "-" + str(HMAX) + "): "
width = eval(input(WIDTH_INPUT))
height = eval(input(HEIGHT_INPUT))
error = False
errorMessage = "\nError: \n"
if width < WMIN or width > WMAX:
error = True
errorMessage += "\tWidth (" +str(width) + ") is not within range (" + str(WMIN) + "-" + str(WMAX) + ")\n"
if height < HMIN or height > HMAX:
error = True
errorMessage += "\tHeight (" +str(height) + ") is not with range ("+ str(HMIN) + "-" + str(HMAX) + ")\n"
if error:
print(errorMessage)
Generated by GNU enscript 1.6.4.