Enter a number, find the number of numbers 3?

You can show an example of how this is done on the pygame library

For a given number (variable or what we enter from the console), find the number of digits 3. If there is no 3-ki then some printf ("no with 3") Thank you in advance!

Author: Эникейщик, 2020-06-12

2 answers

That's how you can:

num = 5467847
if str(num).find('3') == -1:
    print('нет цифры 3')
else:
    print(str(num).count('3'))

Or even so:

num = 5467847
print('нет цифры 3' if str(num).find('3') == -1 else str(num).count('3'))
 2
Author: n1tr0xs, 2020-06-13 03:01:25
number = -521335215432
print(str(abs(number)).count('3'))
 1
Author: user393663, 2020-06-12 14:59:45