python question
lets say you had a string that was returned from a block of code that converted it from letters to numbers.
for example, the user input was "hi", the code converted it into "89" as a string
with a dictionary how could you take that "89" and go back into hi again?
lets say the dictionary was keys and values of keys = alphabet and values = numbers
the output would be back at "hi" again
Convert into numbers
Code :
===================================================
dict1 ={"Hi":89, "Bye":52}
def NumToText(a):
key_list = list(dict1.keys())
val_list = list(dict1.values())
print(key_list[val_list.index(a)])
def TextToNum(a):
print(dict1[a])
print("====Menu====== ")
print("1. Number to Text")
print("2. Text to Number")
n=int(input("Enter Your Choice :"))
if n==1:
a=int(input("Enter a Number (Ex: 89): "))
NumToText(a)
else:
a=input("Enter a Text (Ex: Hi): ")
TextToNum(a)
Get Answers For Free
Most questions answered within 1 hours.