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 sys
def main():
"""
This is where the magic happens.
"""
try:
wantedCount = int(sys.argv[1])
except IndexError as noarg:
desired_length = int(sys.argv[1])
except IndexError:
print("Enter a digit as an argument!")
try:
for i in range(int(wantedCount)):
for i in range(int(desired_length)):
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()
if __name__ == "__main__":
main()