I am trying to play with classes and methods and loops all together in a single module. I am confused as to how my line spacing and naming conventions should be. Please feel free to point out and correct as many styling errors as possible.
filename = 'guest_book.txt'
class Guest:
"""Attempt to model a guest book"""
def __init__(self, guest_name):
self.guest_name = guest_name.title()
def greet_guest(self):
"""Method to greet human scum"""
greeting = f"\nHi {self.guest_name}, Welcome to my kingdom!\n"
print(greeting)
def write_to_guest_book(self):
"""Method to write to guest book"""
with open(filename, 'a') as file_object:
file_object.write(f"{self.guest_name}\n")
def show_guest_book(self):
"""Method to read guest book contents and display them"""
with open(filename, 'r') as file_object:
content = file_object.readlines()
message = f"The following members are in the kingdom currently:\n"
for member in content:
message += member
print(message)
active = True
prompt = f"Please enter your name.\nPress 'q' anytime to quit.\n"
while active:
display = input(prompt).lower()
if display == 'q':
active = False
else:
y = Guest(display)
y.greet_guest()
y.write_to_guest_book()
y.show_guest_book()