Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

# Thread: Having problems with this assignment

1. ## Having problems with this assignment

Hey guys,

So I have this last question in my python lab

Its question # 6 on this page (on the right hand column):
http://goo.gl/rqDwS

My problem is figuring out how to make a loop that checks for each number between 1 and the input N.

For example, if N = 12, I'll need to print a table of numbers from 1-12 and displaying whether each number is perfect, abundant, or deficient.

So far I have only written code that determines what status the value of input N is.

Code:
```def print_table(n):
i = 1
last = n - 1
count = n
while i <= last:
if count % i == 0:
i = i + 1

msg = ''
msg = 'is deficient'
msg = 'is perfect'
msg = 'is abundant'

print n, msg

number = int(input("Enter a number: "))
print_table(number)```
The output of the program should look like this:

Code:
```Enter a number: 12
12 abundant
11 deficient
10 deficient
9 deficient
8 deficient
7 deficient
6 perfect
5 deficient
4 deficient
3 deficient
2 deficient
1 perfect```
Now here is the logic behind it:

12 < 1 + 2 + 3 + 4 + 6
11 > 1
10 > 1 + 2 + 5
9 > 1 + 3
8 > 1 + 2 + 4
7 > 1
6 = 1 + 2 + 3
5 > 1
4 > 1 + 2
3 > 1
2 > 1
1 = 1

So thats why I was thinking of having some kind of while loop that produces different variables like add11, add10, add9, etc to store the sum of the numbers that leave a remainder of 0. But that doesn't seem to be possible.

Thanks for any help on this

• Just do something like:
while i > 0:
print_table(i)
i--

•

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•