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!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1497
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA


Return to General Coding Help

Who is online

Users browsing this forum: Bing [Bot], morissio and 3 guests