Python Forum
Updating An Existing Word and
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Updating An Existing Word and
#1
This how we do it program:

Updating an existing word:
If the user selects to update a word they will be asked to input the word they would like to update.
>>>2
What word do you want to update? home
After inputting their word, the dictionary will check if that word exists in the dictionary if it does not it will print out the following options.
Error the word is not in the dictionary! You may perform these actions:
1. Retry with another word.
2, Return to main menu
>>>
If the user does input a correct word it will ask him for a new updated definition.
What word do you want to update? home
Please write in a new definition: A cozy place
home was updated correctly!



Mycode:
print "Building Dictionary..."
print "Dictionary Built!"
words=["school","teacher","student","classroom"]
definitions=["building structure of education","teach student lessons","people who learning sth","building which students learn sth in school"]
dictionary=dict(zip(words,definitions))
# dictionary method get from stockoverflow

def Menu():
    print ("Please Select one of these options:")
    print ("1. Add a new word")
    print ("2. Update an existing word")
    print ("3. Delete an existing word")
    print ("4. Display a word's definition")
    user_ans=int(input(">>> "))
    return user_ans
user_ans=Menu()

if user_ans==1:
    def adding():
        add1=raw_input("What word do you want to add? ")
        add2=raw_input("Please add in a definition for this word: ")
        for i in add1:
                if add1 in words:
                    continue
                else:
                    words.append(add1)
                    if add2 not in definitions:
                        definitions.append(add2)
                        print add1 + " " + "added in correctly!"

        return dictionary
    adding()
if user_ans==2:
    def update():
        update1=raw_input("What word do you want to update? ")
        if update1 in dictionary.keys():
            update2=raw_input("Please write in a new definition: ")
            newwords=[]
            global definitions
            for item in definitions:
                if item<0:
                    item=0
                    newwords.append(item)
                definitions=newwords
            print definitions
        else:
            print "Error the word is not in the dictionary! You may perfrom these actions:"
            print ("1. Retry with another word")
            print ("2. Return to main menu")
            user_ans2=int(input(">>> "))
            if user_ans==1:
                return update1
            elif user_ans==2:
                return Menu()
    update()
How ı can do it ?
Reply
#2
(Jun-05-2018, 12:24 PM)captainflint Wrote: This how we do it program:

Updating an existing word:
If the user selects to update a word they will be asked to input the word they would like to update.
>>>2
What word do you want to update? home
After inputting their word, the dictionary will check if that word exists in the dictionary if it does not it will print out the following options.
Error the word is not in the dictionary! You may perform these actions:
1. Retry with another word.
2, Return to main menu
>>>
If the user does input a correct word it will ask him for a new updated definition.
What word do you want to update? home
Please write in a new definition: A cozy place
home was updated correctly!



Mycode:
print "Building Dictionary..."
print "Dictionary Built!"
words=["school","teacher","student","classroom"]
definitions=["building structure of education","teach student lessons","people who learning sth","building which students learn sth in school"]
dictionary=dict(zip(words,definitions))
# dictionary method get from stockoverflow

def Menu():
    print ("Please Select one of these options:")
    print ("1. Add a new word")
    print ("2. Update an existing word")
    print ("3. Delete an existing word")
    print ("4. Display a word's definition")
    user_ans=int(input(">>> "))
    return user_ans
user_ans=Menu()

if user_ans==1:
    def adding():
        add1=raw_input("What word do you want to add? ")
        add2=raw_input("Please add in a definition for this word: ")
        for i in add1:
                if add1 in words:
                    continue
                else:
                    words.append(add1)
                    if add2 not in definitions:
                        definitions.append(add2)
                        print add1 + " " + "added in correctly!"

        return dictionary
    adding()
if user_ans==2:
    def update():
        update1=raw_input("What word do you want to update? ")
        if update1 in dictionary.keys():
            update2=raw_input("Please write in a new definition: ")
            newwords=[]
            global definitions
            for item in definitions:
                if item<0:
                    item=0
                    newwords.append(item)
                definitions=newwords
            print definitions
        else:
            print "Error the word is not in the dictionary! You may perfrom these actions:"
            print ("1. Retry with another word")
            print ("2. Return to main menu")
            user_ans2=int(input(">>> "))
            if user_ans==1:
                return update1
            elif user_ans==2:
                return Menu()
    update()
How ı can do it ?

What error are you getting when you run the program?
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020