Created
July 16, 2017 22:17
-
-
Save OmriSama/e5a3ec7e851fda1028650fc47c1b38ce to your computer and use it in GitHub Desktop.
NumberFormatter
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
# simple script where you input 10 digits and it formats it to a U.S phone number | |
def main(): | |
numString = input("Enter a 10 digit US number: ") | |
digits = [] | |
digCount = 0 | |
for dig in numString: | |
if digCount <= 10: | |
if dig.isdigit(): | |
digCount += 1 | |
digits.append(dig) | |
if digCount == 10: | |
print ("+1 (", end = "") | |
for x in range(0, 3): | |
print(digits[x], end = "") | |
print(") ", end = "") | |
for y in range(3, 6): | |
print(digits[y], end = "") | |
print("-", end = "") | |
for z in range(6, len(digits)): | |
print(digits[z], end = "") | |
print() | |
else: | |
print("Sorry. This is an invalid number.") | |
input("Press any key to continue...") | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment