Advertisement
Guest User

Untitled

a guest
Dec 18th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. def checkDigits(uInput): # creates a function that gets a number, and returns it as a sorted list of individual numbers
  2. numbers = []
  3. for i in uInput:
  4. numbers.append(i)
  5. numbers.sort()
  6. return (numbers)
  7.  
  8. myDict = {'1':' minimum ', '2':' '} # dictionary used to change how an input is structured
  9.  
  10. while True: # makes sure that the user successfully decides whether they want to check a range of numbers or a single number
  11. checkType = input("Do you want a range of numbers (1) or a single number (2)")
  12. if checkType in ('1','2'): # allows the code to be ran only if the user has chosen a range or a single number
  13. while True:
  14. checkMin = input("What is the"+ myDict[checkType] +"number you want to check")
  15. if checkType == '1': # needs the maximum number to check for in the range
  16. checkMax = input("What is the maximum number you want to check")
  17. elif checkType == '2':
  18. checkMax = checkMin # sets the maximum number to the minimum number, so that it only checks 1 number
  19. try: # will try to convert the max and min number to an integer, so that if it doesnt work, it will ask the user again
  20. checkMin = int(checkMin)
  21. checkMax = int(checkMax)
  22. if checkMax >= checkMin: # makes sure the max number is larger than the min number, if it is the while loops will be exited, if not it throws an exception and the user will be asked for new numbers
  23. break
  24. else:
  25. raise
  26. except:
  27. print ("Please use a valid number/range of numbers")
  28. break
  29. else:
  30. print("Please only input 1 or 2")
  31.  
  32. foundVal = []
  33.  
  34. for i in range(checkMin, checkMax+1): # will check for all the numbers between the min and the max (will only check once if looking for a specific number)
  35. temp = [] # used to store all of the numbers the anagram number can be multiplied by, will reset for every new number
  36. for j in range(2,10): # checks if the digits are the same as when it is multiplied by every number from 2-9
  37. if checkDigits(str(i)) == checkDigits(str(i*j)):
  38. temp.append(j)
  39. if len(temp) >=1: # if there is 1 or more matches found, this will add the anagram number to the foundValues list, and all the numbers that work with it
  40. foundVal.append([i, temp])
  41.  
  42. for i in foundVal: # prints all of the found anagram numbers + the numbers they work with on their own lines
  43. print (i)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement