-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ascii_Code_Translator.py
105 lines (80 loc) · 3.25 KB
/
Ascii_Code_Translator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# ASCII CODE TRANSLATOR Python program example.
# Created by Joseph C. Richardson, GitHub.com
# Note: you must execute/run the program from
# the OS output screen, via double-clicking the Python
# program file itself.
# HIGHLIGHT AND COPY CODE, THEN PASTE INTO YOUR PREFERABLE PYTHON APP/IDLE
import os,time,math
text_features=(
'cls', # index 0 = clear screen
'\x1b[31m', # index 1 = red
'\x1b[32m', # index 2 = green
'\x1b[33m', # index 3 = yellow
'\x1b[34m', # index 4 = blue
'\x1b[37m' # index 5 = red
)
text_words=(
f'\n{text_features[3]}ASCII CODE NUMERIC VALUE TRANSLATOR\n', # index 0 = text_words
f'\n{text_features[3]}ASCII CODE CHARACTER VALUE TRANSLATOR\n', # index 1 = text_words
f'\n{text_features[3]}ASCII CODE TRANSLATOR', # index 2 = text_words
f'\n{text_features[3]}Thanks for choosing ASCII CODE TRANSLATOR...', # index 3 = text_words
)
word_info=(
f'{text_features[5]}Please type a number, then press \
(Enter) to confirm:{text_features[2]} ', # index 0 = word_info
f'{text_features[5]}Please type a letter key or a number key, then press \
(Enter) to confirm:{text_features[2]} ', # index 1 = word_info
f'\n{text_features[3]}Please choose which ASCII code translator you \
would like to use:\n\n{text_features[5]}Press (1) for ASCII code number \
values.\nPress (2) for ASCII code character values.\nPress \
(Q) to quit.{text_features[2]} ', # index 2 = word_info
f'\n\n{text_features[3]}Do you wish to continue? Press \
(Enter) or press (Q) to quit:{text_features[2]} ', # index 3 = word_info
f'\n{text_features[1]}This is a Value Error!', # index 4 = word_info
f'\n{text_features[1]}This is a Type Error!' # index 5 = word_info
)
button=('1','2','q')
def ascii_codes():
pass
def subroutine1():
while True:
os.system(text_features[0])
print(text_words[0])
try:
ascii_code=int(input(word_info[0]).strip())
ascii_code=input(f'\n{text_features[2]}{chr(ascii_code)}\
{text_features[5]} = ASCII code: " {text_features[2]}{ascii_code}\
{text_features[5]} " {word_info[3]}').lower().lower().strip()
if ascii_code==button[2]:
break
except ValueError:
print(word_info[4])
time.sleep(2)
def subroutine2():
while True:
os.system(text_features[0])
print(text_words[1])
try:
ascii_code=input(word_info[1]).strip()
ascii_code=input(f'\n{text_features[2]}{ascii_code}\
{text_features[5]} = ASCII code: " {text_features[2]}{ord(ascii_code)}\
{text_features[5]} " {word_info[3]}').lower().strip()
if ascii_code==button[2]:
break
except TypeError:
print(word_info[5])
time.sleep(2)
while True:
os.system(text_features[0])
print(text_words[2])
butt=input(word_info[2]).lower().strip()
if butt==button[0]:
subroutine1()
elif butt==button[1]:
subroutine2()
else:
if butt==button[2]:
os.system(text_features[0])
print(text_words[3])
time.sleep(3)
break