Created
July 31, 2019 13:28
-
-
Save gutierrezps/db740e6782d6f9d2c3380d1694d5da70 to your computer and use it in GitHub Desktop.
Zero-padder implementation in Python using math functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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