Valid Mobile Number
Valid Mobile Number
Problem:
The program must accept a list of mobile numbers (in separate lines) as the input. The character q or Q represents the end of the input. The program must print the number of invalid mobile numbers among the given list of mobile numbers as the output. A valid mobile number contains exactly 10 digits.
Input:
9854653221
997878A1576
9992224578
999225789900
986578989B
817524990
Q
Output:
4
Program:
count = 0
total_count = 0
while 1:
number = input().strip()
if number == 'q' or number == 'Q':
break
digit_count = 0
invalid = 0
for i in number:
if i.isdigit():
digit_count += 1
else:
invalid = 1
break
if digit_count == 10 and invalid == 0:
count += 1
total_count += 1
print(total_count - count)
Comments
Post a Comment