Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # A program that takes a 9-non-repeating-digit number and changes it to the next highest number using the same 9 digits
- initialString=input('Please enter a 9-digit number using non-repeating digits:')
- initialNumber=int(initialString)
- number=initialNumber
- exist='no'
- while(len(str(number))<10 and exist=='no'):
- number=number+1
- string=str(number)
- if(string.count('0')==initialString.count('0') and string.count('1')==initialString.count('1') and string.count('2')==initialString.count('2') and string.count('3')==initialString.count('3') and string.count('4')==initialString.count('4') and string.count('5')==initialString.count('5') and string.count('6')==initialString.count('6') and string.count('7')==initialString.count('7') and string.count('8')==initialString.count('8') and string.count('9')==initialString.count('9')):
- exist='yes'
- targetNumber=number
- if(exist=='yes'):
- print('The next highest number is %s.') %targetNumber
- else:
- print('Sorry,',initialNumber,'is the largest number containing the 9 digits.')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement