Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b62f979

Browse files
committed
added solution for 09
1 parent 01dc8a0 commit b62f979

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

09_abuse/abuse.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Author : Martin Schuh <[email protected]>
4+
Date : 2022-11-13
5+
Purpose: Heap abuse
6+
"""
7+
8+
import argparse
9+
import random
10+
from typing import Final
11+
12+
13+
ADJECTIVES: Final = """bankrupt base caterwauling corrupt cullionly detestable
14+
dishonest false filthsome filthy foolish foul gross heedless
15+
indistinguishable infected insatiate irksome lascivious
16+
lecherous loathsome lubbery old peevish rascaly rotten ruinous
17+
scurilous scurvy slanderous sodden-witted thin-faced
18+
toad-spotted unmannered vile wall-eyed"""
19+
20+
NOUNS: Final = """Judas Satan ape ass barbermonger beggar block boy braggart
21+
butt carbuncle coward coxcomb cur dandy degenerate fiend fishmonger
22+
fool gull harpy jack jolthead knave liar lunatic maw milksop minion
23+
ratcatcher recreant rogue scold slave swine traitor varlet villain
24+
worm"""
25+
26+
27+
# --------------------------------------------------
28+
def get_args():
29+
"""Get command-line arguments"""
30+
31+
parser = argparse.ArgumentParser(
32+
description='Heap abuse',
33+
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
34+
35+
parser.add_argument('-a',
36+
'--adjectives',
37+
help='Number of adjectives',
38+
metavar='adjectives',
39+
type=int,
40+
default=2)
41+
42+
parser.add_argument('-n',
43+
'--number',
44+
help='Number of insults',
45+
metavar='insults',
46+
type=int,
47+
default=3)
48+
49+
parser.add_argument('-s',
50+
'--seed',
51+
help='Random seed',
52+
metavar='seed',
53+
type=int,
54+
default=None)
55+
56+
args = parser.parse_args()
57+
58+
if args.adjectives < 1:
59+
parser.error(f'--adjectives "{args.adjectives}" must be > 0')
60+
61+
if args.number < 1:
62+
parser.error(f'--number "{args.number}" must be > 0')
63+
64+
return args
65+
66+
67+
# --------------------------------------------------
68+
def main():
69+
"""Make a jazz noise here"""
70+
71+
adjectives = ADJECTIVES.strip().split()
72+
nouns = NOUNS.strip().split()
73+
74+
assert len(adjectives) == 36
75+
assert len(nouns) == 39
76+
77+
args = get_args()
78+
random.seed(args.seed)
79+
80+
for _ in range(args.number):
81+
# order is important
82+
samples = random.sample(adjectives, k=args.adjectives)
83+
noun = random.choice(nouns)
84+
85+
print(f'You {", ".join(samples)} {noun}!')
86+
87+
88+
# --------------------------------------------------
89+
if __name__ == '__main__':
90+
main()

0 commit comments

Comments
 (0)