+ 2
What's wrong with my code
username = input('Enter your username : ' ) password = input('Enter a strong password : ') While True == True if password <= 8: print('Enter a password longer than 8') continue I keep on getting syntax error : invalid syntax
14 Respostas
+ 7
With first line of your code all is okey, second line you should write in while loop, in your case invalid syntax in fourth line, you should compare length of password with number 8, and operator continue is useless
username = input('Enter your username:')
while True:
password = input('Enter a strong password:')
if len(password) <= 8:
print('Enter a password longer than 8')
else:
break
Next time, insert the code, and do not print it, it's easier to work this way
+ 6
Hmm,
2 things that i noticed:
- inside the while loop there is no 'way out' if password matches the required length. in this case a 'break' is needed.
- JUMP_LINK__&&__Python__&&__JUMP_LINK Learner , why the input for the password is taken as int? 'password = int(input('Enter a strong password : '))' should be a regular string - or ??
+ 5
Hi!
You used capital w for while. Always remember that most of the keywords start with lowercase letter in python.
A condition in a while loop should be ended with colon symbol.
Here is your working code.
username = input('Enter your username : ' )
password = input('Enter a strong password : ')
while True:
if len(password) <= 8:
print('Enter a password longer than 8')
continue
+ 3
Hi Lothar!
Thanks for raising awareness.
That's the beauty of this user-friendly forum. It should be the same as Roma mentioned above. He should use the len() function instead of int() for the password.
I withdrew my words.
+ 2
Lothar , thanks, i correct my code with operator break
+ 2
Thanks guys, I really appreciate
+ 2
Try this:
while True:
password = input('Enter a strong password')
if len(password) <= 8:
password = input('Enter a password longer than 8')
else:
break
+ 2
How about this one? :-
name = input("ENTER THE USERNAME: ")
while len(pas := input()) < 9: print("Enter a password longer than 8 characters")
# Hope this helps
+ 1
Try changing the loop
Not sure but you could have written that part like
While choice==True:
If password.length<=8:
Print(âEnter a password longer than 8â)
Else:
Return true
+ 1
Fatoki Temiloluwa Thanks
+ 1
Dania Farisha Please don't spam.
+ 1
In the while loop the W is w, you miss : and you miss len(password); you have many errors
0
That's why he should do lower() function so it won't be uppercase or lowercase sensitive.
- 2
Mama please