-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFindASCIICode.py
48 lines (42 loc) · 1.51 KB
/
FindASCIICode.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
# ================= Problem Description =================
# This program takes a single character as input from the user and returns its corresponding ASCII value.
#
# ================= Input =================
# - A single character provided by the user.
#
# ================= Output =================
# - The ASCII value of the entered character.
#
# ================= Example =================
# Example 1:
# Input: 'A'
# Output: The ASCII value of A is 65
#
# Example 2:
# Input: 'b'
# Output: The ASCII value of b is 98
# =========================================================
import os
from colorama import Fore, Style
def clear_terminal():
# Clear the terminal screen
os.system('cls' if os.name == 'nt' else 'clear')
clear_terminal()
print(f"{Fore.GREEN}Welcome to ASCII Value Find program{Style.RESET_ALL}")
def find_ASCII_value():
char = input("Enter any character: ")
if len(char) > 1:
print(f"\n{Fore.RED}Sorry!, you can not enter more than one character at a time {Style.RESET_ALL}")
retry = input("Do you want to retry ? (y/q) : ").lower()
if retry != "y":
quit()
else:
print(f"\n{Fore.GREEN}The ASCII value of '{char}' is: {Fore.YELLOW}{ord(char)}{Style.RESET_ALL}")
retry = input("Do you want to retry ? (y/q) : ").lower()
if retry != "y":
quit()
try:
while True:
find_ASCII_value()
except KeyboardInterrupt:
print(f"\n {Fore.YELLOW} Program interrupted. {Fore.GREEN}Exiting gracefully...{Style.RESET_ALL}")