今天写了一些简单的py代码,接了两个单子练了练手。
写了个建议的词典,在里边的单词就直接输出意思,否则输入注释并加入到词典里面。
代码:
words = [] explanations = [] def sort(): n = len(words) for i in range(n): for j in range(i, n): if words[i] > words[j]: word = words[i] explanation = explanations[i] words[i] = words[j] explanations[i] = explanations[j] words[j] = word explanations[j] = explanation while True: word = input('请输入单词:') if word == 'exit': break else: n = len(words) find = False for i in range(n): if words[i] == word: print('释义:'+explanations[i]) find = True break if find is False: explanation = input('请加入单词释义:') words.append(word) explanations.append(explanation) sort()