Completed 10-5 Guest Book
This commit is contained in:
parent
b5e95f55f6
commit
c83a21a61a
21
Chapter_10/10-05_guest_book.py
Normal file
21
Chapter_10/10-05_guest_book.py
Normal file
@ -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")
|
||||||
|
|
||||||
7
Chapter_10/guest-book.txt
Normal file
7
Chapter_10/guest-book.txt
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
James
|
||||||
|
Jimmy
|
||||||
|
David
|
||||||
|
Dan
|
||||||
|
Henry
|
||||||
|
Izakura
|
||||||
|
Paul
|
||||||
Loading…
x
Reference in New Issue
Block a user