-1

I want to append a name entry to a file while the end variable is True, the prompt should reappear every time an entry as been added to the file, the loop should stop once the user enters 'end' or 'no' in the prompt.

here's the what I have tried:

end = True
while end:
    guest = input("Enter your name here: ")
    if guest.lower() =='end' or 'no':
        end= False
        break
    with open('Desktop/guestbook.txt', 'a') as file:
        file.write(f'{guest} visited.\n')
    print(f"You are welcome to SRL, {guest}.")

but it doesn't repeat the prompt, after the first entry the code stops, how can i solve this?

  • 5
    `if guest.lower() =='end' or 'no':` basically means `if bool(guest.lower() =='end') or bool('no'):` and boolean value of any non-empty string is True. So the if is always entered. Try `if guest.lower() in ['end', 'no']:` – h4z3 Aug 08 '23 at 07:22

0 Answers0