From c83a21a61a9aae9450fece506f7093aa2d062d54 Mon Sep 17 00:00:00 2001 From: cheeks <134818917+leftovertoast@users.noreply.github.com> Date: Mon, 3 Mar 2025 18:33:44 +0000 Subject: [PATCH] Completed 10-5 Guest Book --- Chapter_10/10-05_guest_book.py | 21 +++++++++++++++++++++ Chapter_10/guest-book.txt | 7 +++++++ 2 files changed, 28 insertions(+) create mode 100644 Chapter_10/10-05_guest_book.py create mode 100644 Chapter_10/guest-book.txt 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