Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- __author__ = 'Zoap'
- def Search():
- inv = "\nInvalid input"
- invx = "\nNumber to search for must be a number!"
- invs = "\nLength must be a number!"
- print("\nThis program allows you to search for the number of possible combinations of a pin number of length x, "
- "given that you know one of the digits")
- x = str(input("\nInput number to search for: "))
- if x.isdigit() is False:
- print(invx)
- Search()
- return
- elif x.isdigit() is True:
- def PinLength():
- s = str(input("\nInput length of pin code: "))
- if s.isdigit() is False:
- print(invs)
- PinLength()
- return
- elif int(s) > 7:
- print("\nLength can not be more than 7 digits!")
- PinLength()
- return
- import math
- stop = int((math.pow(10, int(s))))
- if stop < int(x):
- print("\nLength of pin makes the number to search for bigger than the possible number of variations!")
- Search()
- return
- elif s.isdigit() is True:
- def CalcForLoop():
- number_list = []
- # For every integer in range add int to list and convert to string
- for i in range(0, (stop + 1)):
- number_list.append(str(i))
- # For every str in list containing x, count x
- x_numbers = [a for a in number_list if x in a]
- # Percent of total numbers in range containing digit x
- percent = len(x_numbers) / (stop / 100)
- if int(x) >= 10:
- print("\nThere are a total of " + str(len(x_numbers)) +
- " numbers between 0 and " + str(stop) + " containing the number " + x)
- print("\nThat is a total of " + str("%.2f" % percent) + "%" " of all numbers between 0 and " +
- str(stop))
- elif int(len(x_numbers)) == 1:
- print("\nThere are a total of " + str(len(x_numbers)) +
- " number between 0 and " + str(stop) + " containing the digit " + x)
- print("\nThat is a total of " + str("%.2f" % percent) + "%" " of all numbers between 0 and " +
- str(stop))
- else:
- print("\nThere are a total of " + str(len(x_numbers)) +
- " numbers between 0 and " + str(stop) + " containing the digit " + x)
- print("\nThat is a total of " + str("%.2f" % percent) + "%" " of all numbers between 0 and " +
- str(stop))
- def RunAgain():
- yes = "y" or "Y"
- no = "n" or "N"
- choice = input("\nRun again? y/n: ")
- if choice is yes:
- Search()
- return
- elif choice is no:
- exit()
- else:
- print(inv)
- RunAgain()
- return
- RunAgain()
- CalcForLoop()
- PinLength()
- Search()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement