Skip to content

Instantly share code, notes, and snippets.

@shorodilov
Created December 19, 2023 14:05
Show Gist options
  • Save shorodilov/0bcbe27b4387c0891011d41d1354c2cd to your computer and use it in GitHub Desktop.
Save shorodilov/0bcbe27b4387c0891011d41d1354c2cd to your computer and use it in GitHub Desktop.
The multipliers of the number's digits
"""
This script will ask the user for an integer number and print out its
multipliers
"""
# collect data
number = int(input("Enter a number: "))
# cast the user's input to a string and print back the multipliers
for power_of_10, multiplier in enumerate(str(number)[::-1]):
print(f"{multiplier} x {10 ** power_of_10}")
@shorodilov
Copy link
Author

This can be modified to more straight-forward approach, while the beginner pythonistas can struggle with reversing the list.

# ... getting the number

power_of_10 = 0

reversed_number = reversed(str(number)) 
for multiplier in reversed_number:
    print(f"{multiplier} x {10 ** power_of_10}")
    power_of_10 += 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment