python/pin.py: modularize

This commit is contained in:
Aminda Suomalainen 2023-10-31 13:34:17 +02:00
parent c88e99a067
commit bbaf5778ef
Signed by: Mikaela
SSH Key Fingerprint: SHA256:CXLULpqNBdUKB6E6fLA1b/4SzG0HvKD19PbIePU175Q

View File

@ -6,14 +6,26 @@ length.
import secrets import secrets
import sys import sys
def main():
"""
This is where the magic happens.
"""
try: try:
wantedCount = int(sys.argv[1]) desired_length = int(sys.argv[1])
except IndexError as noarg: except IndexError:
print("Enter a digit as an argument!") print("Enter a digit as an argument!")
try: try:
for i in range(int(wantedCount)): for i in range(int(desired_length)):
print(secrets.randbelow(10), end="") print(secrets.randbelow(10), end="")
except NameError as noWantedCount: # We satisfy pylint by having the variable here.
# TODO:make this a while loop?
i += 1
except NameError:
print() print()
print() print()
if __name__ == "__main__":
main()