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