USER DIGITS
This is a snippet that extracts each digit from user entered integer input
#!/usr/bin/env python3
def main() -> None:
userInputInt = 0;
ones = 0;
tens = 0;
hundreds = 0;
try:
userInputInt = int(input("Enter a three digit number: "));
except Exception:
print("Invalid input...try again.");
return;
if userInputInt < 100 or userInputInt > 999:
print("Invalid input...try again.");
else:
ones = userInputInt % 10;
userInputInt = userInputInt // 10;
tens = userInputInt % 10;
userInputInt = userInputInt // 10;
hundreds = userInputInt % 10;
userInputInt = userInputInt // 10;
print("First number: ", hundreds);
print("Second number: ", tens);
print("Third number: ", ones);
if __name__ == "__main__":
main();Last updated