0

I am just started to learn Python and I have a probem. I want to make a program that adds books to a list, but allows these 6 possible answers to a question (yes or no), and if someone doesn't answer, it repeats the question.

add = input("Do you want add book?")

while True:
    add != ("no") or ("NO") or ("No") or ("yes") or ("Yes") or ("YES")
    add = input("Do you want add book?")
    if add == ("no") or ("NO") or ("No") or ("yes") or ("YES") or ("Yes"):
        break

Thanks for help.

YBG
  • 1
  • 1
  • 3
    That test doesn't do what you think, but you can write it as `if add.lower() in ["no", "yes"]:` – larsks Jul 28 '23 at 12:17
  • The first line in your *while* loop is irrelevant as you assign something to *add* but then immediately replace it with the return value from *input()* The subsequent test is equivalent to *if add == 'no'* – DarkKnight Jul 28 '23 at 12:26

1 Answers1

0

There are really only two answers because you can normalise the input to a particular case - either upper- or lower-case.

Thus you can simplify your code as follows:

while not (add := input('Do you want to add book? ').lower()) in {'yes', 'no'}:
    print('Please answer yes or no')

print(f'You answered "{add}"')
DarkKnight
  • 19,739
  • 3
  • 6
  • 22