Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def checkDigits(uInput): # creates a function that gets a number, and returns it as a sorted list of individual numbers
- numbers = []
- for i in uInput:
- numbers.append(i)
- numbers.sort()
- return (numbers)
- myDict = {'1':' minimum ', '2':' '} # dictionary used to change how an input is structured
- while True: # makes sure that the user successfully decides whether they want to check a range of numbers or a single number
- checkType = input("Do you want a range of numbers (1) or a single number (2)")
- if checkType in ('1','2'): # allows the code to be ran only if the user has chosen a range or a single number
- while True:
- checkMin = input("What is the"+ myDict[checkType] +"number you want to check")
- if checkType == '1': # needs the maximum number to check for in the range
- checkMax = input("What is the maximum number you want to check")
- elif checkType == '2':
- checkMax = checkMin # sets the maximum number to the minimum number, so that it only checks 1 number
- 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
- checkMin = int(checkMin)
- checkMax = int(checkMax)
- 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
- break
- else:
- raise
- except:
- print ("Please use a valid number/range of numbers")
- break
- else:
- print("Please only input 1 or 2")
- foundVal = []
- 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)
- temp = [] # used to store all of the numbers the anagram number can be multiplied by, will reset for every new number
- for j in range(2,10): # checks if the digits are the same as when it is multiplied by every number from 2-9
- if checkDigits(str(i)) == checkDigits(str(i*j)):
- temp.append(j)
- 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
- foundVal.append([i, temp])
- for i in foundVal: # prints all of the found anagram numbers + the numbers they work with on their own lines
- print (i)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement