Все решения бесполезны, если вы не предотвращаете повторный выход, например. большинство решений будут сдерживать &
до &
.
escapeHtml = function (s) {
return s ? s.replace(
/[&<>'"]/g,
function (c, offset, str) {
if (c === "&") {
var substr = str.substring(offset, offset + 6);
if (/&(amp|lt|gt|apos|quot);/.test(substr)) {
// already escaped, do not re-escape
return c;
}
}
return "&" + {
"&": "amp",
"<": "lt",
">": "gt",
"'": "apos",
'"': "quot"
}[c] + ";";
}
) : "";
};
Это должно сработать. Ошибка, которую я обнаружил, заключалась в том, что вы использовали неправильную структуру данных для хранения своих данных, а также вы повторно инициализировали ее при каждом вводе пользователем, если я правильно понял. Это обновление должно содержать больше книг и отображать их более организованно.
book_list = []
def addBook():
book_dict = {}
book_name = raw_input("Enter the book name: ")
book_dict["Name"] = book_name
author_name = raw_input("Enter the author name: ")
book_dict["Author"] = author_name
publication_name = raw_input("Enter the publication: ")
book_dict["Publication"] = publication_name
publication_year = raw_input("Enter the year of publication year: ")
book_dict["Year"] = publication_year
cost = raw_input("Enter the cost: ")
book_dict["Cost"] = cost
book_list.append(book_dict)
return True
def choose():
print('''************MENU********************
1. Add a book
2. Display a book with a particular name
3. Quit
*****************************************''')
choice = int(input("Enter your choice: "))
if choice == 1:
addBook()
print(book_list)
#elif choice == 2:
# displayBook(books)
elif choice == 3:
exit()
while True:
choose()