NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

import json

def load_dict(file_name):
try:
with open(file_name, 'r') as f:
return json.load(f)
except FileNotFoundError:
return {}

def save_dict(dictionary, file_name):
with open(file_name, 'w') as f:
json.dump(dictionary, f)

def add_word(dictionary):
word = input("Enter the new word: ")
definition = input("Enter the definition: ")
dictionary[word] = definition
print("Word added to dictionary.")

def search_word(dictionary):
word = input("Enter the word to search: ")
if word in dictionary:
print("Definition: ", dictionary[word])
else:
print("Word not found in dictionary.")

def main():
file_name = "dictionary.json"
password = "1234"
dictionary = load_dict(file_name)
while True:
print("Dictionary Menu")
print("1. Add a new word")
print("2. Search for a word")
choice = input("Enter your choice (q to quit): ")
if choice == "1":
pass_check = input("Enter the password to add a new word: ")
if pass_check == password:
add_word(dictionary)
save_dict(dictionary, file_name)
else:
print("Incorrect password. Access denied.")
elif choice == "2":
search_word(dictionary)
elif choice == "q":
break
else:
print("Invalid choice. Please try again.")

if __name__ == '__main__':
main()

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


def create_dictionary(file_name):
"""
Tworzy słownik z pliku, jeśli istnieje, lub tworzy nowy.
"""
try:
with open(file_name, 'r') as file:
dictionary = {}
for line in file:
key, value = line.strip().split(':')
dictionary[key] = value
return dictionary
except FileNotFoundError:
with open(file_name, 'w') as file:
return {}

def add_word(file_name):
"""
Dopisuje nowe słowo do pliku.
"""
key = input("Podaj termin: ")
value = input("Podaj definicję: ")
with open(file_name, 'a') as file:
file.write(f"{key}:{value}n")

def search_word(dictionary):
"""
Wyszukuje termin w słowniku i zwraca jego definicję.
"""
key = input("Podaj termin do wyszukania: ")
if key in dictionary:
print(f"{key}: {dictionary[key]}")
else:
print(f"{key} nie ma w słowniku.")

def display_menu():
"""
Wyświetla menu wyboru.
"""
print("Menu:")
print("1. Dopisanie nowego terminu do pliku")
print("2. Wyszukanie terminu z pliku")
print("0. Wyjście")

if __name__ == '__main__':
file_name = 'dictionary.txt'
dictionary = create_dictionary(file_name)
while True:
display_menu()
choice = input("Wybierz opcję: ")
if choice == '1':
add_word(file_name)
elif choice == '2':
search_word(dictionary)
elif choice == '0':
break
else:
print("Nieprawidłowy wybór.")
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.