dimanche 11 juillet 2021

How to make the code jump back instead of forward [Python]

I was working with a mastermind assignment but one of my define function isn't working as expected.

How do I make the "quit" jump back to "have a guess..." instead of continue to the colourlst?

def valid_usercolour():
    while True:
        #print('Welcome to the Mastermind') 
        usercolour = input('Please have your guess [r,o,y,g]: ').lower()
        if 'quit' in usercolour:    
            while True:
                dc_quit = input('Do you really wanted to quit the game?[y/n]: ')
                if dc_quit.lower() == "y":
                    print()
                    print('Alright, thank You for playing, Goodbye', user_name, '!' )
                    quit()
                    break 
                elif dc_quit.lower() == "n":
                    print("Alright, let's continue to our game")
                    break
                else:
                    print("Sorry! I don't understand what you mean, could you please type only [Y/N]")
                    continue
                      
        colourslist = ['r','o','y','g']
        if any(character not in colourslist for character in usercolour):
            print("Error! Only Characters ,", colourslist, "are allowed")
            continue
        if len(usercolour) != 4:
            print("Error! Only 4 characters are allowed!")
            continue
        break
    return usercolour

Aucun commentaire:

Enregistrer un commentaire