Skip to content

Instantly share code, notes, and snippets.

@rohit-jamuar
Created July 31, 2014 05:56
Show Gist options
  • Save rohit-jamuar/e2f0709446ef035b464a to your computer and use it in GitHub Desktop.
Save rohit-jamuar/e2f0709446ef035b464a to your computer and use it in GitHub Desktop.
Count of numbers (in range [1,input_num]) which don't have 'exclude'
#!/usr/bin/python
def number_counting(input_num, exclude):
'''
Returns the count of numbers (in range [1,input_num]) which don't
have 'exclude' among their constituent digits.
'''
if type(input_num) == int and type(exclude) == int:
exclude = str(exclude)
if len(exclude) == 1:
count = 0
for number in range(1, input_num+1):
temp = str(number)
if exclude not in temp:
count += 1
return count
else:
return "Argument 'exclude' should be a digit!"
else:
return "Argument 'input_num' and/or 'exclude' should be an integer!"
if __name__ == '__main__':
print number_counting(1000, 7)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment