Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

negative number factor 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 :: replace word in column pandas lambda 
Python :: what is *args and **kwargs in django 
Python :: how to make my discord bot shut down with a command 
Python :: huggingface dataset from pandas 
Python :: join to dataframes pandas 
Python :: zip multiple lists 
Python :: get multiple inputs in python using map 
Python :: add image pptx python 
Python :: coding planets 
Python :: sentiment analysis french python 
Python :: import yaml python3 
Python :: boxplot show values seaborn 
Python :: enter selenium in python 
Python :: how to set and run flask app on terminal 
Python :: how to download a project from pythonanywhere 
Python :: Converting categorical feature in to numerical features 
Python :: read data from s3 bucket python 
Python :: python request coinmarketcap 
Python :: python run batch file 
Python :: python download file from ftp 
Python :: python memory usage 
Python :: how to merge between two columns and make a new one in pandas dataframe 
Python :: cv2.flip 
Python :: 405 status code django 
Python :: stop function python 
Python :: python string to list of int 
Python :: read and write to file python 
Python :: python timeit 
Python :: pyqt remove widget 
Python :: python reading csv files from web 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =