uVA 382(https://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=318) is rather simple: Given a number, say whether it's a perfect, deficient or abundant number. But it seems that I have a problem with the formatting. Here's what the problem wants:
The first line of output should read ‘PERFECTION OUTPUT’. The next N lines of output should list for each input integer whether it is perfect, deficient, or abundant, as shown in the example below. Format counts: the echoed integers should be right justified within the first 5 spaces of the output line, followed by two blank spaces, followed by the description of the integer. The final line of output should read ‘END OF OUTPUT’.
Here's my code:
def sum_divisors(n):
sm = 0
for i in range(1, n):
if n % i == 0:
sm += i
return sm
n = list(map(int, input().split()))
n.pop()
print("PERFECTION OUTPUT")
for i in n:
sm = sum_divisors(i)
if sm == i:
state = "PERFECT"
if sm < i:
state = "DEFICIENT"
if sm > i:
state = "ABUNDANT"
spaces = ' ' * (5 - len(str(i)))
print("{}{} {}".format(spaces, i, state))
print("END OF OUTPUT")
Now, I've already tried using uDebug with many different outputs and I've gotten the right answer and I don't think the problem is with the algorithm. I think it's about the formatting of the output but don't know what I got wrong.