Silly responses for failed attempts

- This is over engineered, I was just trying out an idea
 - MessageTable implements a Random Distribution System
 - Changed the alignment of the output messages to lineup.
This commit is contained in:
Pilot 2020-09-15 14:39:17 -04:00
parent 30f54f438f
commit 80e36e4aa5
2 changed files with 42 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
__pycache__/

41
witty_retort.py Normal file
View File

@ -0,0 +1,41 @@
import random
import functools
class MessageTable:
contents = []
def add_entry(self, string, probability):
entry = {
"remark": string,
"probability": probability,
"table": self
}
self.contents.append(entry)
def get_message(self):
probability_sum = functools.reduce(
lambda total, entry:
entry["probability"] + total,
self.contents, 0
);
hit_value = random.randrange(probability_sum)
running_value = 0
for i in self.contents:
running_value += i["probability"]
if hit_value < running_value:
return i
remarks = MessageTable()
remarks.add_entry("Not quite", 30)
remarks.add_entry("Keep trying", 20)
remarks.add_entry("Intresting strategy", 15)
remarks.add_entry("Close", 10)
remarks.add_entry("Don't give up", 10)
remarks.add_entry("I though you had it", 10)
remarks.add_entry("You can do it!", 5)