Compare commits
2 Commits
6c01a4f55c
...
6eedb471f2
| Author | SHA1 | Date | |
|---|---|---|---|
|
6eedb471f2
|
|||
|
7e6e33397d
|
+32
@@ -0,0 +1,32 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
r"""
|
||||||
|
Python loops demo
|
||||||
|
|
||||||
|
License: This program is released under the MIT License
|
||||||
|
"""
|
||||||
|
import logging
|
||||||
|
logging.basicConfig(level=logging.INFO, format="%(funcName)s %(levelname)s: %(message)s")
|
||||||
|
|
||||||
|
def while_loop() -> None:
|
||||||
|
counter: int = 1
|
||||||
|
while counter <= 5:
|
||||||
|
logging.info(counter)
|
||||||
|
counter += 1
|
||||||
|
|
||||||
|
def for_loop() -> None:
|
||||||
|
for i in range(5):
|
||||||
|
logging.info(i)
|
||||||
|
|
||||||
|
# Main function
|
||||||
|
def main() -> None:
|
||||||
|
"""
|
||||||
|
Both functions will log a message 5 times, but the for loop is so much simpler
|
||||||
|
|
||||||
|
"""
|
||||||
|
while_loop()
|
||||||
|
for_loop()
|
||||||
|
|
||||||
|
|
||||||
|
# Call main function
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
Executable
+21
@@ -0,0 +1,21 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import petname
|
||||||
|
import secrets
|
||||||
|
|
||||||
|
def generate_password(names: int) -> str:
|
||||||
|
"""
|
||||||
|
Generate a password from pet names and a random number
|
||||||
|
|
||||||
|
:param names: Number of names to generate
|
||||||
|
:return: A simple yet secure password
|
||||||
|
"""
|
||||||
|
results = []
|
||||||
|
for _ in range(names):
|
||||||
|
results.append(petname.Name().capitalize())
|
||||||
|
results.append(str(secrets.randbelow(8999)+1000))
|
||||||
|
return ".".join(results)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
print(generate_password(2))
|
||||||
Reference in New Issue
Block a user