Skip to content

Instantly share code, notes, and snippets.

@gutierrezps
Created July 31, 2019 13:28
Show Gist options
  • Save gutierrezps/db740e6782d6f9d2c3380d1694d5da70 to your computer and use it in GitHub Desktop.
Save gutierrezps/db740e6782d6f9d2c3380d1694d5da70 to your computer and use it in GitHub Desktop.
Zero-padder implementation in Python using math functions
import math
def main():
while True:
inputStr = input('Type a number: ')
if inputStr == '':
break
inputNumber = int(inputStr)
a = inputNumber
if inputNumber % 10 == 0:
a = inputNumber + 1
number = (4 - math.ceil(math.log10(a + 0.2))) * '0' + str(inputNumber)
print(str(inputNumber % 10) + ' ' + str(math.log10(a)) + ' ' + str(math.ceil(math.log10(a))) )
print('Number zero-padded with 4 digits: ' + number)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment