Commit ca011f60 by 大雄

第二次作业

parents
# words = ["gin", "zen", "gig", "msg"]
def fuc(words):
morse = [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."]
print("摩尔斯密码中含有的密码为" + '%d' % len(morse) + "个") # 确认morse密码的个数
print('----------------')
letters = "abcdefghijklmnopqrstuvwxyz"
mor_code = "" # 表示空字符串使用"",而[]的输出和""不同
# mor_codes = [] #写法2,定义一个没有长度的list
str
mor_codes = [] * len(words) #写法1,建立一个有长度的list
# words = input("请输入单词列表\n")
for i in range(len(words)):
mor_code = ""
for j in range(len(words[i])):
letter = words[i][j]
seq = letters.index(letter)
mor_code = mor_code + morse[seq] # 建立每个单词的摩尔斯密码字符串
# print(mor_code)
mor_codes.insert(i,mor_code) # 写法1,建立摩尔斯密码的list,list的添加元素函数insert
# mor_codes.append(mor_code)
# print(mor_codes)
print("转换出的摩尔斯密码为 " + str(mor_codes))
print('----------------')
print("转义的摩尔斯密码有" + str(len(set(mor_codes))) + "种")
return str(len(mor_codes))
# print("转义的摩尔斯密码有%d" %(len(set(mor_codes))))
words = ["ginadd", "zenddds", "gidfag", "msdddsdafg","msdddssdfafg"]
fuc(words)
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