๐Ÿ“– Beginning Python Programming /
Module: Controlling logic flow

while ...:

๐Ÿ“– Beginning Python Programming / Controlling logic flow / while ...:

Code example: While-Input-List v2

guests = []

while True:
    value = input("Please input a guest name, or 'q' to quit: ")
    if value == "q":
        break
    if len(value) > 0:
        guests.append(value)

if len(guests) > 0:
    with open("guests.txt", "w") as file_obj:
        file_obj.write("\n".join(guests))

print("List saved to guests.txt.")