String - ASCII Converter

 Description:- The programme changes the string from user input to list of ASCII values and vice-versa.

Source Code given below:-


def str_ascii(txt):
asciis = []
for char in txt:
asciis.append(ord(char))
return asciis

def ascii_str(lst):
text = ""
for num in lst:
text = text + chr(num)
return text

try:
decide = int(input("Press 1 to change String to ASCII.\nPress 2 to change ASCII to String : "))


if decide == 1:
usr_str = input("Enter your string : ")
res = str_ascii(usr_str)
print("ASCII values : ", res)

elif decide == 2:
ascii_list = [int(num) for num in input("Enter ASCIIs values saperated by , : ").split(",")]
res = ascii_str(ascii_list)
print("String : ", res)
else:
print("Invalid Input! Try again...")

except ValueError:
print("Please choose a number only.")

Comments