+ 3
[SOLVED] Can someone please tell me what is wrong with this code?
It's for the Password Validation code coach. Line 7 is producing an error. My code: p = input() count = 0 for x in p: if x == '!' or '@' or '#' or '
#x27; or '%' or '&' or '*': count += 1 i = 0 if x in p.isdigit(): i+=1 if count == 2 and i == 2 and len(p) >= 7: print('Strong') else: print('Weak')16 ответов
+ 6
Ava Alford ,
there are some issues in the code, see it slightly fixed :
https://code.sololearn.com/cxMPEy39hx4K/?ref=app
+ 5
These ifs need changing:
if x=='!' or x=='@' or x=='#' or x=='#x27; or x=='%' or x=='&' or x=='*':
if count>=2 and i>=2 and len(p)>=7:
+ 4
Thank you Lothar and John Wells.
+ 4
John Doe ,
can you please explain your doubts on using .isdigit() ?
thanks!
+ 4
John Doe , yes I'm sure that isdigit() works in this scenario ; however, I get your point about using more descriptive variable names. Thank you for the advice. The code works now after making some adjustments and now I understand the places where I went wrong. This has been a learning experience for me.
+ 2
I forgot about that. Wow! I can't believe I forgot. Thank you so much!
+ 2
Lothar I was referring to the code in the original question
+ 2
John Doe ,
ok- now it's clear. thanks for your answer!
+ 2
Duah Obeng Dennis, this is a place u can learn over 20+ programming languages and u are asking someone to teach u?
+ 1
Do yourself a favor and use more descriptive variable naming.
„count“: it tells that it counts something, that is good, bit you are counting multiple things. Name it something like special_character_count.
„i“: not very descriptive, it only reveqls that it‘s (probably) an integer. Why not digit_count (if that is what it‘s supposed to do). Are you sure isdigit() does what you think it does?
+ 1
Wow. So there's a method called isdigit(). Then I get suspicious and look up isalpha(). Bam, there it is.
And because I had known about neither, I had had to make a string for both to search over when I did my PV exercise.
I think an exercise is potentially the equivalent of 3 exercises or more, should you decide to tweak it or use a different approach.
I wish my kind(noobs in degrees) asked more questions like this.
+ 1
Nothing wrong just the owner of this code is the wrong peroson 😈
0
I need someone to teach me programming
0
Duah Obeng Dennis what language do you want to learn?
0
I think he should start with python
0
Python is easy