I haven't really understood error 1) unless you want the last line in the menu
to be printed without a newline but I am not certain that that is your problem.
The second error is easier to explain.
You are sorting the dictionary "phonebook" when you write it to the file but a dictionary is not possible to sort, it is by default unsorted, so it has no effect or at least it doesn't have the effect you expect. To write it in a sorted way, sort just the keys:
to be printed without a newline but I am not certain that that is your problem.
The second error is easier to explain.
You are sorting the dictionary "phonebook" when you write it to the file but a dictionary is not possible to sort, it is by default unsorted, so it has no effect or at least it doesn't have the effect you expect. To write it in a sorted way, sort just the keys:
for rec in sorted(phonebook.keys()):and delete the line
sorted = {k : phoneBook[k] for k in sorted(phoneBook)}The function call
sorted(phoneBook)gives you a sorted list with the keys so
for rec in sorted(phonebook):would work as well.