Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

factors for negative number python

def factorspos(x):
    x = int(x)
    factorspos = []
    print("The factors of",x,"are:")
    if x > 0: # if input is postive
        for i in range(1,x+1):
            if x % i == 0:
                factorspos.append(i)
                print(i)
        return factorspos
    elif x < 0: #if input is negative
        for i in range(x,0):
            if x % i == 0:
                factorspos.append(i)
                print(i)
        return factorspos


print(factorspos(12))   #outputs [1, 2, 3, 4, 6, 12]
print(factorspos(-12))  #outputs [-12, -6, -4, -3, -2, -1]
Comment

PREVIOUS NEXT
Code Example
Python :: How to send Email verification codes to user in Firebase using Python 
Python :: pandas -inf and inf to 0 
Python :: strip in python 
Python :: python get element from dictionary 
Python :: python telegram bot 
Python :: continue vs pass python 
Python :: .describe() python 
Python :: extract name of file from path python 
Python :: planets with python coding 
Python :: python longest list in list 
Python :: python snake case to camel case 
Python :: sha256 decrypt python 
Python :: python strptime() 
Python :: export flask app 
Python :: python word starts with 
Python :: Handling categorical feature 
Python :: method for detect that a float number is integer in python 
Python :: remove specific character from object in pandas column using iloc 
Python :: Range python iterate by 2 
Python :: rock paper scissors python 
Python :: merge all mp4 video files into one file python 
Python :: python list pop multiple 
Python :: generate rsa key python 
Python :: how to know if a key is in a dictionary python 
Python :: next iteration python 
Python :: np.where 
Python :: xpath starts-with and ends-with 
Python :: duplicate in list 
Python :: django group with permission 
Python :: dot operator in python 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =