def createdictionary():
    mydictionary = dict()
    mydictionary['Computer']='Computer is an electronic machine.'
    mydictionary['RAM']='Random Access Memory'
    return mydictionary
def insert(dictionary):
    print("Enter the keyword you want to insert in the dictionary: ")
    key=input()
    print("Enter its meaning")
    meaning=input()
    dictionary[key]=meaning
    f = open('dict_bckup.txt','a')
    f.write(key)
    f.write('=')
    f.write(meaning)
    f.write(';\n')
    f.close()
    print("Do you want to insert again? y/n")
    ans=input()
    if ( ans == 'y' or ans=='Y' ):
        insert(dictionary)
def display(dictionary):
    print("The contents of the dictionary are : ")
    f = open('dict_bckup.txt','r')
    print(f.read())
    f.close()
def update(dictionary):
    print("Enter the word whose meaning you want to update")
    key=input()
    #i want to edit the meaning of the key in the text file
    f = open('dict_bckup.txt','w')
    if key in dictionary:
        print(dictionary[key])
        print("Enter its new meaning: ")
        new=input()
        dictionary[key]=new
    else:
        print("Word not found! ")
    print("Do you want to update again? y/n")
    ans=input()
    if (ans=='y' or ans=='Y'):
        update(dictionary)
def search(dictionary):
    print("Enter the word you want to search: " )
    word=input()
    if word in dictionary:
        print(dictionary[word])
else:
    print("Word not found! ")
print("Do you want to search again? y/n")
ans=input()
if(ans=='y' or ans=='Y'):
    search(dictionary)
def delete(dictionary):
    print("Enter the word you want to delete: ")
    word=input()
    if word in dictionary:
        del dictionary[word]
        print(dictionary)
    else:
        print("Word not found!")
    print("Do you want to delete again? y/n ")
    ans=input()
    if ( ans == 'y' or ans == 'Y' ):
        delete(dictionary)
def sort(dictionary):
    for key in sorted(dictionary):
        print(" %s: %s "%(key,(dictionary[key])))
def main():
    dictionary=createdictionary()
    while True:
        print("""             Menu
            1)Insert
            2)Delete
            3)Display Whole Dictionary
            4)Search
            5)Update Meaning
            6)Sort
            7)Exit
          Enter the number to select the coressponding field """)
        ch=int(input())
        if(ch==1):
            insert(dictionary)
        if(ch==2):
            delete(dictionary)
        if(ch==3):
            display(dictionary)
        if(ch==4):
            search(dictionary)
        if(ch==5):
            update(dictionary)
        if(ch==6):
            sort(dictionary)
        if(ch==7):                                        
            break
main()
私はpythonが初めてです。私はこれを手に入れるために何日も努力してきました。しかし、まだ解決策は見つかりませんでした。問題は、最初に、単語とその意味を保存する簡単な辞書プログラムを作成したことです。それから、単語を永久に保存する必要があると思いました。単語をテキストファイルに保存して表示しようとしました。しかし、テキストファイル内の単語を検索する方法がわかりません。そして、単語を見つけて、その意味を更新したいとします。では、どうすればよいのでしょうか。「w」を使用してテキストファイル全体を書き換えると、書き換えられます。また、どのように削除すればよいですか。ファイルのテキストに単語を挿入した方法も間違っていることはわかっています。これで私を助けてください。