# Design a Program to Count Numbers that don’t Contain 3 in Python

Given the list of numbers, the task is to count the Numbers which doesn’t contain Digit 3 in them.

Examples:

Example1:

Input:

Given list =[125, 94, 32, 138, 349, 5783, 12394297, 975686138, 3589295]

Output:

The Count of numbers that doesnt contain three in the given list [125, 94, 32, 138, 349, 5783, 12394297,
975686138, 3589295] is [ 2 ]

Example2:

Input:

Given list =[2949, 1358, 927482, 6582913, 19, 24, 123, 56723, 194]

Output:

The Count of numbers that doesnt contain three in the given list [2949, 1358, 927482, 6582913, 19, 24, 123,
56723, 194] is [ 5 ]

## Design a Program to Count Numbers that don’t Contain 3 in Python

Below are the ways to count the Numbers which doesn’t contain Digit 3 in them.

Want to excel in java coding? Practice with these Java Programs examples with output and write any kind of easy or difficult programs in the java language

### Method #1: Using For Loop (Static Input)

Approach:

• Give the list as static input and store it in a variable.
• Take a variable that stores the count of numbers that doesn’t contain digit 3 in them(say cunt)
• Traverse the given list using For loop.
• Convert the list element to a string and store it in a variable.
• Check if this string contains digit 3 in it using not in operator and If statement.
• If it is true then increment the cunt by 1.
• Print the cunt value.
• The Exit of the program.

Below is the implementation:

# Give the list as static input and store it in a variable.
lstnmbs = [2949, 1358, 927482, 6582913, 19, 24, 123, 56723, 194]
# Take a variable that stores the count of numbers
# that doesn't contain digit 3 in them(say cunt)
cunt = 0
# Traverse the given list using For loop.
for numbr in lstnmbs:
# Convert the list element to a string and store it in a variable.
strnumbr = str(numbr)
# Check if this string contains digit 3 in it using not in operator and If statement.
if '3' not in strnumbr:
# If it is true then increment the cunt by 1.
cunt = cunt+1
# Print the cunt value.
print('The Count of numbers that doesnt contain three in the given list',
lstnmbs, 'is [', cunt, ']')


Output:

The Count of numbers that doesnt contain three in the given list [2949, 1358, 927482, 6582913, 19, 24, 123,
56723, 194] is [ 5 ]

### Method #2: Using For Loop (User Input)

Approach:

• Give the list as user input using list(),map(),input(),and split() functions.
• Store it in a variable.
• Take a variable that stores the count of numbers that doesn’t contain digit 3 in them(say cunt)
• Traverse the given list using For loop.
• Convert the list element to a string and store it in a variable.
• Check if this string contains digit 3 in it using not in operator and If statement.
• If it is true then increment the cunt by 1.
• Print the cunt value.
• The Exit of the program.

Below is the implementation:

# Give the list as user input using list(),map(),input(),and split() functions.
# Store it in a variable.
lstnmbs = list(map(int, input(
'Enter some random List Elements separated by spaces = ').split()))
# Take a variable that stores the count of numbers
# that doesn't contain digit 3 in them(say cunt)
cunt = 0
# Traverse the given list using For loop.
for numbr in lstnmbs:
# Convert the list element to a string and store it in a variable.
strnumbr = str(numbr)
# Check if this string contains digit 3 in it using not in operator and If statement.
if '3' not in strnumbr:
# If it is true then increment the cunt by 1.
cunt = cunt+1
# Print the cunt value.
print('The Count of numbers that doesnt contain three in the given list',
lstnmbs, 'is [', cunt, ']')


Output:

Enter some random List Elements separated by spaces = 125 94 32 138 349 5783 12394297 975686138 3589295
The Count of numbers that doesnt contain three in the given list [125, 94, 32, 138, 349, 5783, 12394297, 975686138, 3589295] is [ 2 ]

Related Programs: