Commit 554dc04b by yanjun13

提交第三次作业摩斯密码

parent f37222ff
words = ["gin", "zen", "gig", "msg"]
mima = {"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":"--.."}
word = ""
s = ""
list_code = []
count = 0
#外层循环获取字符gin
for i in words:
#内层循环获取字母对应的摩斯密码
for j in i:
word += mima[j]
#将对应字符gin的摩斯密码组合放入s
s = word
if s not in list_code:
count += 1
#将不一样的摩斯密码组合放入list_code
list_code.append(s)
#清空组合的摩斯密码以便外层循环存放新的摩斯密码
word = ""
print(count)
print(list_code)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment