lundi 2 décembre 2019

restart if statement without restarting entire loop?

I want to design a 'survey' inspired by a flow chart and I can't understand why it's not working. I want something simple without packages since I haven't wrapped my head around them yet.

How it should work:

Q1 - input is yes -> Q2 - input yes - Q3 -> input yes - ... - Q9 - input no -> Q10

Q1 - input is no -> break

Q1 - input maybe -> Q1 AGAIN

When I currently input anything different from yes or no it starts from the beginning (Q1).. can I make it repeat the IF statement in all the questions until input is yes or no??

while True:
    x = input ('question_text' )
    if x.lower () == 'yes':
        x = input ( 'question2_text' )
        if x.lower () == 'yes':
            x = input ( 'question3_text' )
            if x.lower () == 'yes':
                          ETC... 
            if x.lower () == 'no':
                print ( 'No.' )
                break
            else:
                print ('ONLY YES/NO')
        if x.lower () == 'no':
            print ( 'No.' )
            break
        else:
            print ('ONLY YES/NO')
    if x.lower () == 'no':
        print ( 'No.' )
        break
    else:
        print ('ONLY YES/NO')

Aucun commentaire:

Enregistrer un commentaire