+ 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

3rd Aug 2021, 11:04 AM
Amuwa Timothy
Amuwa Timothy - avatar
14 Réponses
+ 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
3rd Aug 2021, 11:24 AM
Roma Butaku
Roma Butaku - avatar
+ 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 ??
3rd Aug 2021, 12:25 PM
Lothar
Lothar - avatar
+ 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
3rd Aug 2021, 11:18 AM
Python Learner
Python Learner - avatar
+ 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.
3rd Aug 2021, 3:34 PM
Python Learner
Python Learner - avatar
+ 2
Lothar , thanks, i correct my code with operator break
3rd Aug 2021, 12:31 PM
Roma Butaku
Roma Butaku - avatar
+ 2
Thanks guys, I really appreciate
3rd Aug 2021, 12:48 PM
Amuwa Timothy
Amuwa Timothy - avatar
+ 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
4th Aug 2021, 6:54 AM
Idoredid123
Idoredid123 - avatar
+ 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
5th Aug 2021, 5:32 AM
Calvin Thomas
Calvin Thomas - avatar
+ 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
4th Aug 2021, 12:00 PM
Fatoki Temiloluwa
4th Aug 2021, 3:27 PM
Amuwa Timothy
Amuwa Timothy - avatar
+ 1
Dania Farisha Please don't spam.
5th Aug 2021, 11:06 AM
Calvin Thomas
Calvin Thomas - avatar
+ 1
In the while loop the W is w, you miss : and you miss len(password); you have many errors
12th Dec 2021, 8:32 PM
CGO!
CGO! - avatar
0
That's why he should do lower() function so it won't be uppercase or lowercase sensitive.
13th Dec 2021, 6:17 AM
Idoredid123
Idoredid123 - avatar
- 2
Mama please
5th Aug 2021, 9:37 AM
Dania Farisha
Dania Farisha - avatar