Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,907 questions

51,839 answers

573 users

How to check if an integer include specific digits x times in Python

1 Answer

0 votes
def has_digit_x_times(number, digit, xtimes):
    # Convert the number and digit to strings
    number_str = str(number)
    digit_str = str(digit)
    
    # Count the occurrences of the digit in the number
    count = number_str.count(digit_str)
    
    # Check if the count matches the desired number of times
    return count == xtimes

number = 7097175
digit = 7
xtimes = 3

result = has_digit_x_times(number, digit, xtimes)

print(result) 



'''
run:

True

'''

 



answered Apr 26, 2025 by avibootz
...