+ 3
How to check if string has some numbers
I want to create a program that Checks if a string has 2 numbers from 1-9 and 2 of the letters from QWERTY Which loop should I use Please Help
2 Réponses
+ 4
string = "aQSY34"
nums = len([n for n in string if n in "123456789"])
letters = len([c for c in string if c in "QWERTY"])
print(nums == 2 and letters == 2)
0
It's easy as drinking water🤣😎... Why do you want to ask this to others...😮😥😪
Anyways
Loop through each character in string,
Check if it is 1,
Check if it is 0