Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pickle
- try:
- knowledge = pickle.load(open("knowledge.p", "rb"))
- except FileNotFoundError:
- print("Knowledge file not found, creating new")
- knowledge = {}
- pickle.dump(knowledge, open("knowledge.p", "wb"))
- knowledge = pickle.load(open("knowledge.p", "rb"))
- def getChoice():
- while True:
- print("Would you like to know somthing or are you going to tell me somthing?")
- choice = input("you: ")
- if choice == 'know':
- print("What would you like to know?")
- return choice
- elif choice == 'tell':
- print("Ok, what are you going to tell me about?")
- return choice
- else:
- print("Im sorry what??")
- def getYesNo():
- while True:
- yesNo = input("you: ").lower()
- if yesNo == 'yes':
- return yesNo
- elif yesNo == 'no':
- return yesNo
- else:
- print("Im sorry what??")
- def tellMe():
- thing = input("you: ")
- if thing in knowledge:
- definition = knowledge[thing]
- print("I already know what", thing, "is. It's", definition)
- return (thing, definition)
- else:
- print("And what's that?")
- definition = input("you: ")
- return (thing, definition)
- def checkTell(thing, definition):
- while True:
- print("So", thing, "is", definition, "right?")
- yesNo = getYesNo()
- if yesNo == 'no':
- print("Then what is", thing, "?")
- definition = input("you: ")
- else:
- print("Ok great")
- return (thing, definition)
- while True:
- choice = getChoice()
- if choice == 'tell':
- (thing, definition) = tellMe()
- (thing, definition) = checkTell(thing, definition)
- knowledge.update({thing: definition})
- pickle.dump(knowledge, open("knowledge.p", "wb"))
- elif choice == 'know':
- skip = False
- query = input("you: ")
- if query == 'everything':
- print("Ok here it is!\n", knowledge, '\n')
- skip = True
- if skip == False:
- if query in knowledge:
- result = knowledge[query]
- print("I think that", query, "is", result, "... Am I right?")
- yesNo = getYesNo()
- if yesNo == 'yes':
- print("Great!")
- if yesNo == 'no':
- thing = query
- print("So what is a", thing, "?")
- definition = input("you: ")
- (thing, definition) = checkTell(thing, definition)
- knowledge.update({thing: definition})
- pickle.dump(knowledge, open("knowledge.p", "wb"))
- else:
- print("Sorry I don't know about", query, "would you like to tell me about it?")
- yesNo = getYesNo()
- if yesNo == 'yes':
- thing = query
- print("So what is a", thing, "?")
- definition = input("you: ")
- (thing, definition) = checkTell(thing, definition)
- knowledge.update({thing: definition})
- pickle.dump(knowledge, open("knowledge.p", "wb"))
- else:
- print("Maybe later then")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement