+ 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 Answers
+ 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