Connecting Tech Pros Worldwide Forums | Help | Site Map

Need a hint with problem

Newbie
 
Join Date: Oct 2009
Posts: 5
#1: Oct 23 '09
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.

Expand|Select|Wrap|Line Numbers
  1. # User input
  2. num = int(raw_input("Determine the factors of what number ? "))
  3.  
  4. # Display factors in one line
  5. print "The factors are:",
  6.  
  7. # Variable set
  8. test = 1
  9.  
  10. # Calcualte factors
  11. for test in range(num):
  12.     if num%test == 0:
  13.         print num,
  14.  
  15. # Print a blank space
  16. print
I don't want a solution I just want a hint to what i'm doing wrong.

kaarthikeyapreyan's Avatar
Member
 
Join Date: Apr 2007
Location: India
Posts: 101
#2: Oct 23 '09

re: Need a hint with problem


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.
Reply