So my task is this: A number, n, is called lean if the sum of all its factors is n + 1. A number, n, is called fat if the sum of all its factors is greater than 3*n. A number, n, is called Jack Sprat if it is both lean and the next number, n + 1 is fat.
I have to ask the user to input a number and I have to say whether it is lean, fat or Jack Sprat. I also have to print all the numbers that are jack sprat from 1 to 10000 in 1 second.
This program takes about 10 seconds to do that
Here is the Code:
def isLean(n, t):
if t == n + 1:
return True
else:
return False
def isFat(n, t):
if t > 3*num:
return True
else:
return False
def isJackSprat(n, t, t2):
if t == n+1 and t2 > 3*(n+1):
return True
else:
return False
num = int(input("Please enter a number: "))
total = 0
total2 = 0
total3 = 0
total4 = 0
prime = ""
for factor in range(1,num+1):
if num % factor == 0:
total += factor
for factor in range(1,num+2):
if (num+1) % factor == 0:
total2 += factor
if isLean(num,total) == True:
print ("Lean: Yes")
elif isLean(num,total) == False:
print ("Lean: No")
if isFat(num,total) == True:
print ("Fat: Yes")
elif isFat(num,total) == False:
print ("Fat: No")
if isJackSprat(num, total, total2) == True:
print ("Jack Sprat: Yes")
elif isJackSprat(num, total, total2) == False:
print ("Jack Sprat: No")
print ("These are the Jack Sprat Numbers from 1 - 1000")
for count in range (1,10000):
if count % 2 != 0:
for factor in range (1,count+ 1):
if factor % 2 != 0:
if count % factor == 0:
total3 += factor
for factor in range (1,count+2):
if (count+1) % factor == 0:
total4 += factor
if total3 == (count + 1) and total4 > 3*(count + 1):
prime = prime + str(count) + ", "
total3 = 0
total4 = 0
print (prime[0:len(prime)-2])
I would really appreciate it if I can get some help