dimanche 23 octobre 2016

Python 3.5: Nested While Loops With If/Elif/Else Statements [duplicate]

This question already has an answer here:

I'm a beginner on Python who started only a few months ago, and I seem to be having a problem with the following code:

forenamee = ()
while forenamee != ("yes") or ("Yes") or ("YES") or ("no") or ("No") or   ("NO"):
forenamee = input("Would you like your protaganist to have a first name?")
if forenamee ==  ("yes") or forenamee == ("Yes") or forenamee == ("YES"):
    forename = input("What would you like your protaganist's first name to be?")
    print ("Your protaganist's first name is " +forename)
    correct0 = ()
    while correct0 != ("no") or ("No") or ("NO"):
        correct0 = input("Is that correct?")
        if correct0 == ("yes") or correct0 == ("Yes") or correct0 == ("YES"): 
            break
        elif correct0 == ("no") or correct0 == ("No") or correct0 == ("NO"):
            print ("Please choose another first name.")
            correct0 = ()
        else:
            print ("That decision is not available.")
elif forenamee == ("no") or forenamee == ("No") or forenamee == ("NO"):
    import random
    forename = ("Sam", "Ashley", "Charlie", "Jamie", "Alex", "Robin", "Cameron")
    print ("Your protaganist's first name will be '" +(random.choice(forename)) +"' by default")
    break
else:
    print ("That decision is not available.")
break

Everything works as it should except for the 'Is this correct?' loop which you get when 'Yes' is typed for the variable 'forename'. If you get asked 'Is this correct?' and type in 'Yes', the code will progress as planned and continues onto the next code. However, if 'No' or anything else apart from 'Yes' is entered then it goes back to 'Is this correct?' For this code, I'm wanting it to go back to the question/loop that says 'What would you like your protagonist's name to be?'. How would I do this?

Aucun commentaire:

Enregistrer un commentaire