diff --git a/Chapter_10/10-05_guest_book.py b/Chapter_10/10-05_guest_book.py new file mode 100644 index 0000000..8777bdd --- /dev/null +++ b/Chapter_10/10-05_guest_book.py @@ -0,0 +1,21 @@ +# Exercise 10-5 Guest Book +# Learning Objective: Save by appending to a file. + +from pathlib import Path + +path = Path('./Chapter_10/guest-book.txt') + +current_guest = "" + +guest_list = "" + +actively_asking = True +while actively_asking: + current_guest = input("Enter a guest name, when done type (n/N):\n\t") + if current_guest.lower() != 'n': + guest_list += current_guest + "\n" + else: + actively_asking = False +path.write_text(guest_list) +print("Guest book updated") + diff --git a/Chapter_10/guest-book.txt b/Chapter_10/guest-book.txt new file mode 100644 index 0000000..ae3ceed --- /dev/null +++ b/Chapter_10/guest-book.txt @@ -0,0 +1,7 @@ +James +Jimmy +David +Dan +Henry +Izakura +Paul