Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Find Factors of a Number using While Loop

print("Enter the Number: ")
num = input()

num = int(num)
print("
Factors of", num)

i = 1
while i<=num:
    if num%i==0:
        print(i)
    i = i+1
Comment

Find Factors of a Number using While Loop with validation

print("Enter a Number: ", end="")
try:
    num = int(input())

    print("
Factors of " +str(num)+ " are: ", end="")
    i = 1
    while i<=num:
        if num % i == 0:
            print(i, end=" ")
        i = i + 1
    print()
except ValueError:
    print("
Invalid Input!")
Comment

Find Factors of a Number Using for Loop

print("Enter a Number: ", end="")
try:
    num = int(input())

    print("
Factors of " +str(num)+ " are: ", end="")
    for i in range(1, num+1):
        if num % i == 0:
            print(i, end=" ")
    print()
except ValueError:
    print("
Invalid Input!")
Comment

PREVIOUS NEXT
Code Example
Python :: Code Example of Checking if a variable is None using is operator 
Python :: Code Example of Comparing None with empty string 
Python :: Convert Int to String Using string formatting 
Python :: Simple Python Permutation Without Passing any argument 
Python :: Add OR Concatenation of Tuples in python 
Python :: matplotlib legend from scratch 
Python :: how to decide that the input must be a integer less than 5 in python 
Python :: python create named timer 
Python :: install Social Auth App Flask 
Python :: how to find the index of a specific number in pythong? 
Python :: jdoodle python 
Python :: vorticity 
Python :: *9c0xxbz] 
Python :: counter and element of list for loop python 
Python :: Find meta tag of a website in python 
Python :: Python NumPy atleast_1d Function Example when inputs are in high dimension 
Python :: how to change the color of console output in python to green 
Python :: Python3: Deleting even and only showing uneven numbers from, set list. 
Python :: Python NumPy vstack Function Syntax 
Python :: configure socketio static file python 
Python :: max index tuple 
Python :: modles en django 
Python :: python multiply function with return keyword 
Python :: pymenu example 
Python :: turn dictionary into flat list 
Python :: how to avoind DeprecationWarning in python 
Python :: knn compute_distances_no_loop 
Python :: python random number between 1000 and 9999 
Python :: How to allow discord bot to respond to webhook. Python. Discord.py 
Python :: Flask_SQLAlchemy is claiming my value is not boolean 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =