vendredi 29 septembre 2017

below is my code, i can't figure out why break statement is working for all cases? and not returning for new loop [duplicate]

This question already has an answer here:

import json
from difflib import get_close_matches
data= json.load(open("data.json"))
def dictionary(word):
    word=word.lower()
    if word in data:
        return data[word]
    elif len(get_close_matches(word,data.keys()))>0:
        response=input("Did you mean %s instead? If yes enter Y: "% get_close_matches(word,data.keys())[0])
        if response=='Y'or'y':
            return data[get_close_matches(word,data.keys())[0]]
    else:
        print("Word does not exist. Please double check it! ")
        return ""

while True:
    word=input("Search your word: ")
    result=(dictionary(word))
    for ans in result:
        print(ans)
    demand=input("To close type 'Y' else 'N': ")
    if demand == 'Y' or 'y':
        break

Aucun commentaire:

Enregistrer un commentaire