+ 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

12th Jan 2021, 7:20 AM
Yusuf M Hashmi
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)
12th Jan 2021, 9:08 AM
David Ashton
David Ashton - avatar
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
12th Jan 2021, 7:22 AM
Steve Sajeev
Steve Sajeev - avatar