1

The updated code for the errors, it now can succesfully check for enters and maximum and minimum valuesThe updated code for the errors, it now can succesfully check for enters and maximum and minimum valuesThe updated code for the errors, it now can succesfully check for enters and maximum and minimum values

print("------------------------------------------------------------------------")
print('''Welcome to password Locker, a place where you can 
store all your passwords to easily enter your precious accounts without
hassle.''')
print("------------------------------------------------------------------------")



print('''First lets make an account,''')

while True:
    first_name = input('''What is your first name?''')
    if first_name.isdigit():  #isdi
        print("No numbers")
    else:
        print("Eligible")
        break

while True:
        sur_name = input('''What is your surname?''')
        if sur_name.isdigit():  #isdi
            print("No numbers")
        else:
            print("Eligible")
            break

print('''----------------------------------''')
print('''Welcome, {} {} 
what would you like your username to be, it should be something 
memorable and no longer than ten characters long'''.format(first_name, sur_name))
while True:
        username = input("")
        if 0 < len(username) < 10:
                print('''Nice, username''')
                break
        elif not username:
            pass

        else:
            print('''Your username should be a maximum of 10 charecters''')
while True:
    locker_password = input('''Now it's time to setup a password for your locker: ''')
    if len(locker_password) > 4 and len(locker_password) < 11:

        print('''{}, is locked in thanks for joining Password Locker'''.format(locker_password))       
    else:
        print("It should be between 4 and 10 charecters long!")```


  [1]: https://i.stack.imgur.com/4JnoH.png
  • Replace that `continue` with a `break` and add a `if username != "":` check. – Aran-Fey Mar 21 '19 at 08:41
  • @ Aran-Fey replace it but it still reasks the question instead of saying the messege below ``` else: print('''Your username should be a maximum of 10 charecters''')``` –  Mar 21 '19 at 08:44
  • What username did you input? – Aran-Fey Mar 21 '19 at 08:46
  • @Aran-Fey I inputed one larger than 10 charecters –  Mar 21 '19 at 08:50
  • I can't reproduce that. The code correctly checks the length of the input. If you've *only* replaced the `continue` with a `break`, it should work. If it doesn't work, you must've messed something up. – Aran-Fey Mar 21 '19 at 08:53
  • 1
    The new code works fine. – Aran-Fey Mar 21 '19 at 08:58

1 Answers1

0

Add and elif with a condition and modify the if condition a little:

username = input('''Welcome, {} {} 
what would you like your username to be, it should be something 
memorable and no longer than ten characters long
'''.format(first_name, sur_name))
while True:
        username = input()
        if 0 < len(username) < 10:
                print('''Nice, username''')
                break
        elif not username:
            pass

        else:
            print('''Your username should be a maximum of 10 charecters''')

Example output:

Welcome, Bob Smith 
what would you like your username to be, it should be something 
memorable and no longer than ten characters long

Welcome, Bob Smith 
what would you like your username to be, it should be something 
memorable and no longer than ten characters long
12133254827258426763589
Your username should be a maximum of 10 charecters
Welcome, Bob Smith 
what would you like your username to be, it should be something 
memorable and no longer than ten characters long
abc
Nice, username
U13-Forward
  • 69,221
  • 14
  • 89
  • 114
  • hi @U9-Forward, I put your code in it still dosnt print the Your username should be a maximum of 10 charecters could there be a problem with the rest of my code? –  Mar 21 '19 at 08:52
  • @hobo Can you copy the whole code and try it again? – U13-Forward Mar 21 '19 at 08:53
  • I did put the whole code still not showing that messege, just repeating the messege –  Mar 21 '19 at 08:55
  • @hobo That's strange, it works well for me – U13-Forward Mar 21 '19 at 08:57
  • just inutted my whole code hope fully that helps –  Mar 21 '19 at 08:59
  • @hobo It works perfectly fine for me, are sure you entered a more than 10 character input? – U13-Forward Mar 21 '19 at 09:02
  • I put a photo of my output, and it just asks question again –  Mar 21 '19 at 09:04
  • @hobo It is there! right under the input! – U13-Forward Mar 21 '19 at 09:06
  • Oh yeah I see it does, but how can I make it so It dosnt repeat the first question agian, only prints that it has to be a maximum of 10 charecters –  Mar 21 '19 at 09:07
  • Move the question out of the loop (with `print`, not `input`) and use an `input()` with no text inside the loop. – Aran-Fey Mar 21 '19 at 09:08
  • @hobo You mean it won't ask again? – U13-Forward Mar 21 '19 at 09:09
  • @ U9-Forward so basically when the user inputs more than 10 chearecters I want it to just print ```print('''Your username should be a maximum of 10 charecters''')``` instead of both the above but and '''Welcome, {} {} what would you like your username to be, it should be something memorable and no longer than ten characters long''' –  Mar 21 '19 at 09:16
  • @Aran-Fey that worked thanks, –  Mar 21 '19 at 09:17
  • @U9-Forward I think I fixed it ill update the code now –  Mar 21 '19 at 09:17
  • @hobo Now? edited mine – U13-Forward Mar 21 '19 at 09:18
  • @U9-Forward @ Aran-Fey ```elif username != "": print("please enter vaild response") break``` I aded this so if the person just preses enter but the code completely ignores it –  Mar 21 '19 at 09:27