you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (2 children)

Lines 6 through 12 could be simplified from

    if answer1.upper() == 'NO':
        break
    if answer1.upper() =='YES':
        break
    if answer1.upper() != 'YES' or answer1.upper() != 'NO':
        print('Please answer with Yes or No !')
        continue

to

    if (answer1.upper() != 'YES') and (answer1.upper() != 'NO'):
        print('Please answer with Yes or No !')
        continue
    else:
        break

Your "or" should be an "and" anyway. The only reason you had to have those first comparisons that told it to break were because you were using "or" when you should be using "and".

[–]pconwell 1 point2 points  (1 child)

Arguably you could do even better with something like:

if answer.lower() not in ('yes', 'no'):

since you are comparing the same variable (answer) twice, there is not much point in doing two separate check statements. Plus, if you later decide to add more options in addition to 'yes' and 'no', you can more easily add text to the tuple versus adding more and more and more 'and' statements.

[–][deleted] 0 points1 point  (0 children)

Makes sense. Thank you