我正在尝试用Python编写一个程序:
这就是我一直在做的事情,但它似乎不适用于需要首先执行添加的10以上的数字。
def prime_digit_sum(number):
n = (number)
temp = n = int(n)
remainder = sum = 0
while ( temp > 0) :
remainder = temp % 10
temp = temp/10
sum= sum +remainder
if number == 2:
return 1
elif number == 3:
return 1
if number <= 1 or number%2==0:
return 0
check=3
maxneeded=number
while check<maxneeded+1:
maxneeded=number/check
if number%check==0:
return 0
check+=2
return 1
while(True):
text = input("please enter an integer: ")
if (text == 'q'):
break
number = int(text)
result = prime_digit_sum(number)
if (result == None):
continue
if result:
print("the sum of digits of", number, "is a prime number")
else:
print("the sum of digits of", number, "is not a prime number")
print()
print("exiting")