Need a hint with problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • theroflchopper
    New Member
    • Oct 2009
    • 5

    Need a hint with problem

    Ok I'm having a error with my program. Which finds and displays all positive factors of an input integer. I either get it listing 1 factor num times or an error that I can't divide by zero but I don't know why.

    Code:
    # User input
    num = int(raw_input("Determine the factors of what number ? "))
    
    # Display factors in one line
    print "The factors are:",
    
    # Variable set
    test = 1
    
    # Calcualte factors
    for test in range(num):
        if num%test == 0:
            print num,
    
    # Print a blank space
    print
    I don't want a solution I just want a hint to what i'm doing wrong.
    Last edited by bvdet; Oct 23 '09, 08:20 PM. Reason: Add code tags
  • kaarthikeyapreyan
    New Member
    • Apr 2007
    • 106

    #2
    range(num) starts from 0. if u specify range(5) its value would be [0,1,2,3,4].
    modify the range args to get your desired output, and you need not really set the variable test in your case. the other error is that you are printing the num that you want to find the factors for and not the factors themself.

    Comment

    Working...