Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- def main():
- preparedList = [] #Gör list för ord
- dictionaryList = [] #Gör list för beskrivning
- while 1 == 1:
- print "Menu for dictionary"
- print "1: Insert"
- print "2: Lookup"
- print "3: Delete a word"
- print "4: Exit program"
- menyval = raw_input("Choose alternative(posetive integer): ")
- if menyval=="1":
- insert(preparedList, dictionaryList)
- elif menyval=="2":
- lookup(preparedList, dictionaryList)
- elif menyval=="3":
- deleteaword(preparedList, dictionaryList)
- elif menyval=="4":
- break #avsulta loopen.
- else:
- print "****"
- print "You didnt type in a number in the right range (1-4)"
- print "****"
- def insert(preparedList, dictionaryList):
- insertWord = raw_input("Word to insert: ").lower()
- insertExp = raw_input("Describe the item: ").lower()
- if insertWord.lower() in preparedList: #Kolla ifall ordet redan finns
- print "****"
- print "That word already exists, try again."
- print "****"
- elif insertWord.isspace() or insertExp.isspace(): #Kolla ifall det bara är spaces.
- print "****"
- print "You need to write something, not just spaces."
- print "****"
- elif len(insertWord) == 0 or (insertExp) == 0: #kolla så användaren inte bara trycker enter
- print "****"
- print "You need to write something, not just enter or a single character.."
- print "****"
- else:
- preparedList.append(insertWord) #Lägg till ord i preparedList
- dictionaryList.append(insertExp) #Lägg till beskrivning i dictionaryList
- print "----"
- print "Sucessfully inserted", insertWord, "into the wordlist"
- print "----"
- return
- def lookup(preparedList, dictionaryList):
- searchedWord = raw_input("What word do you want to search for?: ").lower()
- if searchedWord in preparedList: #Sök igenom preparedList för ordet först.
- getIndex = preparedList.index(searchedWord) #index av vart ordet som söks ligger (int)
- print "----"
- print "Descrition for",searchedWord,":",dictionaryList[getIndex] #använd getIndex för att få rätt plats på beskrivning
- print "----"
- else:
- print "****"
- print "That word does not exist."
- print "****"
- def deleteaword(preparedList, dictionaryList):
- print "These are the words in your wordlist: "
- print "----"
- for item in preparedList: #printa ut alla orden som finns i preparedList
- print item,
- print ""
- print "----"
- deleteWord = raw_input("What word would you like to delete: ").lower()
- if deleteWord in preparedList: #kolla ifall ordet finns i preparedList
- getIndex = preparedList.index(deleteWord) #Ännu en gång, ta index för vart ordet finns i sin lista
- preparedList.remove(deleteWord) #ifall det finns, delete:a det.
- del dictionaryList[getIndex] #använd getIndex för att deleta den rätta beskrivningen.
- print "----"
- print "Sucessfully deleted", deleteWord, "from the wordlist"
- print "----"
- else:
- print "****"
- print "That word doesnt exist in our wordlist."
- print "****"
- return
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement