摩斯电码与字母相互转换

raw_input() 将所有输入作为字符串看待,返回字符串类型。而 input() 在对待纯数字输入时具有自己的特性,它返回所输入的数字的类型( int, float )。
python3之后input默认输入str格式
while True:
value = input("input:")
ARR = ('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '1', '2', '3', '4', '5', '7', '8', '9', '0')
arr = ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '1', '2', '3', '4', '5', '7', '8', '9', '0')
list = ('.-', '-...', '-.-.', '-..', '.', '..-.', '--.', '....', '..', '.---', '-.-', '.-..', '--', '-.', '---', '.--.', '--.-', '.-.', '...', '-', '..-', '...-', '.--', '-..-', '-.--', '--..', '.----', '..---', '...--', '....-', '.....', '-....', '--...', '---..', '----.', '-----')

if value in ARR:
li = list[ARR.index(value)]
print(li)
elif value in arr:
lis = list[arr.index(value)]
print(lis)
elif value in list:
ar = ARR[list.index(value)]
print(ar)
else:
print("请输入字母或者摩斯电码")
原文地址:https://www.cnblogs.com/hadean/p/7651546.html