Advertisement
Adehumble

Week4 Coding Exercise 11

Feb 22nd, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.68 KB | None | 0 0
  1. #11
  2. print("This program is written to calculates and return all the factors of a whole number")
  3. print("|||||"*24)
  4.  
  5.  
  6. #My Function Program
  7. def factors(expected_no):
  8.     factors=[]
  9.     if expected_no<0:
  10.         print("Error! You must enter a POSTIVE whole number.\nPlease, try again!")
  11.     for i in range(1,expected_no+1):
  12.         if 1<=i<=expected_no and expected_no%i==0:
  13.             factors.append(i)
  14.        
  15.     print("The factors of", expected_no,"in ascending order is: ",factors)
  16.        
  17.  
  18. #My Main Program
  19. while True:
  20.     try:
  21.         user_no=int(input("enter the number: "))
  22.         break
  23.     except ValueError:
  24.         print("oops! That is a wrong input.\nYou MUST enter a positive whole number")
  25.         print("|||||"*24)
  26.    
  27. factors(user_no)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement