Beispiel #1
0
from Number_Operations import digits
print("Spy Numbers -> A number whose sum of cube of digits = number")
while True:
    string = input("Enter a range upto which you want the Spy numbers ")
    if string == "":
        break
    try:
        number = int(string)
    except:
        print("Invalid Input")
        continue
    print("Spy numbers upto",number,"are:")
    for i in range(0,number+1):
        sum = 0
        product = 1 
        split = digits(i)
        for j in split:
            sum += j
            product *= j
        if product == sum:
            print(i)
print("Spy numbers Code Ended")



from Number_Operations import digits
print(
    "Palindrome Numbers -> A number that is the same written forwards or backwards"
)
condition = True
while True:
    string = input("Enter next number to be checked ")
    if string == "":
        break
    try:
        number = int(string)
    except:
        print("Invalid Input")
        continue
    split = digits(number)
    split_2 = split[::-1]
    if split == split_2:
        print(number, "is a palindrome number.")
    else:
        print(number, "is not a palindrome number.")
print("Palindrome numbers Code Ended")
Beispiel #3
0
from Number_Operations import digits
print(
    "Automorphic Numbers -> A number whose square ends with the number itself")
while True:
    string = input(
        "Enter a range upto which you want the automorphic numbers ")
    if string == "":
        break
    try:
        number = int(string)
    except:
        print("Invalid Input")
        continue
    print("Automorphic numbers upto", number, "are:")
    for i in range(0, number + 1):
        condition = True
        split = digits(i)
        square_split = digits(i * i)
        length = len(split)
        for j in range(0, length):
            if split[j] != square_split[j]:
                condition = False
        if condition:
            print(i)
print("Automorphic numbers Code Ended")
Beispiel #4
0
from Number_Operations import digits
print("Happy Numbers -> Repeated sum of squares of digits = 1")
condition = True
while(condition):
    string = input("Enter next number to be checked ")
    if string == "":
        break
    try:
        number = int(string)
    except:
        print("Invalid Input")
        continue
    while (number != 1) and (number != 4) and (number != 0): 
        factors = digits(number)
        number = 0
        for i in factors:
            number += i*i
            print(" +",i,"^2")
        print(" = ",number)
        if (number == 1) or (number == 4):
            break
    if number == 1:
        print(number,"is a happy number.")
    else:
        print(number,"is a sad number.")
print("Happy numbers Code Ended")