[SOLVED] Can someone please tell me what is wrong with this code? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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')

21st Apr 2022, 1:40 PM
Ava Alford
16 Answers
+ 6
Ava Alford , there are some issues in the code, see it slightly fixed : https://code.sololearn.com/cxMPEy39hx4K/?ref=app
21st Apr 2022, 2:27 PM
Lothar
Lothar - avatar
+ 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:
21st Apr 2022, 2:13 PM
John Wells
John Wells - avatar
+ 4
Thank you Lothar and John Wells.
21st Apr 2022, 2:36 PM
Ava Alford
+ 4
John Doe , can you please explain your doubts on using .isdigit() ? thanks!
22nd Apr 2022, 9:49 AM
Lothar
Lothar - avatar
+ 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.
22nd Apr 2022, 1:15 PM
Ava Alford
+ 2
I forgot about that. Wow! I can't believe I forgot. Thank you so much!
21st Apr 2022, 2:28 PM
Ava Alford
+ 2
Lothar I was referring to the code in the original question
22nd Apr 2022, 11:13 AM
John Doe
+ 2
John Doe , ok- now it's clear. thanks for your answer!
22nd Apr 2022, 11:52 AM
Lothar
Lothar - avatar
+ 2
Duah Obeng Dennis, this is a place u can learn over 20+ programming languages and u are asking someone to teach u?
28th Apr 2022, 6:12 AM
Aarav
Aarav - avatar
+ 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?
22nd Apr 2022, 5:48 AM
John Doe
+ 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.
23rd Apr 2022, 10:54 AM
Korkunç el Gato
Korkunç el Gato - avatar
+ 1
Nothing wrong just the owner of this code is the wrong peroson 😈
23rd Apr 2022, 1:40 PM
some1gr8b4u
some1gr8b4u - avatar
0
I need someone to teach me programming
23rd Apr 2022, 6:50 AM
Duah Obeng Dennis
Duah Obeng Dennis - avatar
0
Duah Obeng Dennis what language do you want to learn?
28th Apr 2022, 2:59 PM
Ava Alford
0
I think he should start with python
28th Apr 2022, 3:07 PM
Aarav
Aarav - avatar
0
Python is easy
28th Apr 2022, 3:07 PM
Aarav
Aarav - avatar