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

PREVIOUS NEXT
Code Example
Python :: Code Example of Checking if a variable is None using == operator 
Python :: Command to install Voluptuous Python Library 
Python :: Convert Int to String Using F-strings 
Python :: Simple Python Permutation Printing result without for loop 
Python :: Creating a list with several elements that are distinct or duplicate 
Python :: Grading program using if else 
Python :: extract tables from image python 
Python :: for i in range(6, 11): print(i, end="") 
Python :: python occ display point 
Python :: python gender input 
Python :: python set vs tuple performance 
Python :: vortex core line detection 
Python :: Sequential Execution EC2 
Python :: build numpy array 
Python :: How to srape all links from a website in python 
Python :: Python NumPy transpose Function Example in one line of code 
Python :: python terminal color 
Python :: Set changed size during iteration 
Python :: Python NumPy vstack Function Example with 1d array 
Python :: configure socketio static file python specific content type 
Python :: pytorch Jaccard Index 
Python :: how to fetch limited rows in pandas dataframe using sqlalchemy 
Python :: godot knockback 
Python :: lambda function in python to shut ec2 at the time zone 
Python :: opensource ip tracker python 
Python :: Use PIP from inside script 
Python :: make dialog in the front by Pywinauto 
Python :: find smallest element not present in list python 
Python :: heatmap colorbar label 
Python :: first duplicate 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =