Skip to content Skip to sidebar Skip to footer

How To Loop Back To The Beginning Of The Code On Python 3.7

After I type 5 usernames, it stops itself. How can I prevent that. username = ['admin','bill','kevin','mike','nick'] for user in username: name = input('Please enter a username:

Solution 1:

username = ['admin','bill','Kevin','mike','nick']
whileTrue :

    name =input("Please enter a username: ")
    if name=='admin' :
        print("Hello "+ name + " ,would you like to see a status report?")
        breakelif name in username :
        print("Hello " + name.title() + " thank you for logging in!")
        breakelse:
        print("Who are you " + name.title() + " ? ")

Solution 2:

You can use infinity loop. This is an example. "while True" works forever.

username = ['admin','bill','kevin','mike','nick']  
whileTrue:
    name = input("What's your nickname?")
    if(name in username):
        print("Hello " + name + "! Thank you for logging in!")

Solution 3:

I think you might be looking something like this:

username = ['admin','bill','Kevin','mike','nick']
whileTrue:
    whileTrue :
    name = input("Please enter a username: ")
    if name=='admin' :
        print("Hello "+ name + " ,would you like to see a status report?")
        answer = input()
        if answer == 'yes':
            print('report')
        break;

    if name in username :
        print("Hello " + name.title() + " thank you for logging in!")
        break;
    else:
        print("Who are you " + name.title() + " ? ")
        break;

Use a while True loop inside another so whenever the second loop breaks, will loop back to the first one.

Hope this help.

Post a Comment for "How To Loop Back To The Beginning Of The Code On Python 3.7"