Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

While looping for multiple choice questions?

So this is what I'm trying to work with. I want Yes and No to both equal the same thing and end the loop (that I haven't started yet), though when something is typed in that isn't Yes or No it loops the question again until yes or no is inputed. I'm having trouble figuring out how to do this part, I'm still learning and while loops are new ground for me.

I'm using 2.7

d1 = raw_input('Please answer with Yes or No.\n')
if d1 == 'Yes':
    print('Good, let\'s begin.')
elif d1 == 'No':
    print('Good, let\'s begin.')
if d1 == 'yes':
    print('Good, let\'s begin.')
elif d1 == 'no':
    print('Good, let\'s begin.')
else:
    ps('Mmmmm...')
like image 551
Jay Avatar asked Jul 17 '26 00:07

Jay


1 Answers

Try this:

while True:
    d1 = input('Please answer with Yes or No.\n')
    if d1.lower() in ('yes', 'no'):
        print('Good, let\'s begin.')
        break
    else:
        print('MMMMmm')
like image 65
amarynets Avatar answered Jul 18 '26 15:07

amarynets



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!