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.

40,011 questions

51,958 answers

573 users

How to check if a number is cyclops (number with odd number of digits and zero in the center) in Python

3 Answers

0 votes
import math 

def isCyclopsNumber(n) :
    if (n == 0) :
        return True
    m = n % 10
    count = 0
    
    while (m != 0) :
        count += 1
        n = math.floor(n / 10)
        m = n % 10
    
    n = math.floor(n / 10)
    m = n % 10
    
    while (m != 0) :
        count -= 1
        n = math.floor(n / 10)
        m = n % 10
    
    return n == 0 and count == 0

print(("yes" if isCyclopsNumber(209) else "no"))
print(("yes" if isCyclopsNumber(18037) else "no"))
print(("yes" if isCyclopsNumber(5604) else "no"))



'''
run:

yes
yes
no

'''

 



answered Apr 10, 2023 by avibootz
edited Apr 10, 2023 by avibootz
0 votes
def isCyclopsNumber(n) :
    if (n == 0) :
        return True
    m = n % 10
    count = 0
    
    while (m != 0) :
        count += 1
        n = n // 10
        m = n % 10
    
    n = n // 10
    m = n % 10
    
    while (m != 0) :
        count -= 1
        n = n // 10
        m = n % 10
    
    return n == 0 and count == 0

print(("yes" if isCyclopsNumber(209) else "no"))
print(("yes" if isCyclopsNumber(18037) else "no"))
print(("yes" if isCyclopsNumber(5604) else "no"))



'''
run:

yes
yes
no

'''

 



answered Apr 10, 2023 by avibootz
0 votes
def isCyclopsNumber(num) :
    s = str(num)
    
    if not len(s) % 2 :
        return False
    
    if not s.count('0') == 1: 
        return False
    
    mid_index = len(s) // 2
    if s[mid_index] == '0' :
        return True
    
    return False

print(("yes" if isCyclopsNumber(209) else "no"))
print(("yes" if isCyclopsNumber(18037) else "no"))
print(("yes" if isCyclopsNumber(5604) else "no"))




'''
run:

yes
yes
no

'''

 



answered Apr 10, 2023 by avibootz
...