Need help plz

This is the place for queries that don't fit in any of the other categories.

Need help plz

Postby xjaram1 » Tue Sep 17, 2013 4:51 pm

I need help with my code, I have most done I just can't get my divisors to be in order from least to greatest. I tried making i = N then i = i - 1 that doesn't give me 9/9 but 9/3 and 9/1. Any help will be appreciated.








Code: Select all
#This program gets a integer from the user in the range of 1 and 100.
#The program will make sure the integer is between that range, and it will then list the divisors of N.
#In order least to greatest
while True:
    N = int(input("Enter N:"))
    if 1 <= N <= 100:
        break
    else :
        print("Please enter only numbers in the range [1,100].")

i = 0

print("The divisors of",N,"are:",end = " ")
while 1 <= N <= 100:
        i = i + 1
        if N%i == 0:
            print(N//i,end = " ")
            #div = N//i
            #print(div, end = " ")
        if i == N:
            break


Code: Select all
SHELL:

Python 3.3.2 (v3.3.2:d047928ae3f6, May 13 2013, 12:45:22)
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>>
Enter N:9
The divisors of 9 are: 9 3 1
>>>
Last edited by micseydel on Tue Sep 17, 2013 5:29 pm, edited 1 time in total.
Reason: First post lock.
xjaram1
 
Posts: 1
Joined: Sat Aug 24, 2013 9:37 pm

Re: Need help plz

Postby micseydel » Tue Sep 17, 2013 5:31 pm

Try using a for loop instead of a while loop, to start. That always simplifies things.
Join the #python-forum IRC channel on irc.freenode.net!
User avatar
micseydel
 
Posts: 1131
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA


Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 2 guests