Advertisement
Guest User

Untitled

a guest
Jan 27th, 2015
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. # A program that takes a 9-non-repeating-digit number and changes it to the next highest number using the same 9 digits
  2. initialString=input('Please enter a 9-digit number using non-repeating digits:')
  3. initialNumber=int(initialString)
  4. number=initialNumber
  5. exist='no'
  6. while(len(str(number))<10 and exist=='no'):
  7. number=number+1
  8. string=str(number)
  9. 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')):
  10. exist='yes'
  11. targetNumber=number
  12. if(exist=='yes'):
  13. print('The next highest number is %s.') %targetNumber
  14. else:
  15. print('Sorry,',initialNumber,'is the largest number containing the 9 digits.')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement