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 ]
- Python Program to Check a Number is Spy number
- Python Program to Check if a Number is Peterson Number
- Python Program to Check If A Number Is A Happy Number
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:
- python program to generate a dictionary that contains numbers between 1 and n in the form x xx
- python program to count the number of digits present in a number
- python program to count set bits in a number
- python program to calculate the average of numbers in a given list
- python program to print sum of negative numbers positive even numbers and positive odd numbers in a list
- python program to print all numbers in a range divisible by a given number
- python program to count the frequency of words appearing in a string using a dictionary