Initial implementation
This commit is contained in:
parent
d436e7ae37
commit
eabfa933d2
50
elisa_pl.py
50
elisa_pl.py
@ -1 +1,49 @@
|
||||
print("Hello, World!")
|
||||
import re
|
||||
import random
|
||||
|
||||
ARG_LITERAL = '%'
|
||||
GOODBYES =["Do zobaczenia", "Elo"]
|
||||
QUIT = "wyjscie"
|
||||
|
||||
pairs = ( ('test (.*)', ('%1',)), ('test2 (.*)', ('%1 2',)) )
|
||||
|
||||
|
||||
def main():
|
||||
is_running = True
|
||||
while is_running:
|
||||
user_input = input().lower()
|
||||
|
||||
if should_quit(user_input):
|
||||
is_running = False
|
||||
continue
|
||||
|
||||
for pair in pairs:
|
||||
search = re.search(pair[0].lower(), user_input)
|
||||
|
||||
if not search:
|
||||
continue
|
||||
|
||||
ans = pick_answer(pair)
|
||||
print(substitute_arg(ans, search.groups()))
|
||||
|
||||
print(random.choice(GOODBYES))
|
||||
|
||||
|
||||
def should_quit(input):
|
||||
return QUIT in input
|
||||
|
||||
|
||||
def substitute_arg(pattern, sub):
|
||||
# TODO: More than one argument support
|
||||
arg = ARG_LITERAL + '1'
|
||||
return pattern.replace(arg, sub[0])
|
||||
|
||||
|
||||
def pick_answer(pair):
|
||||
assert len(pair) == 2
|
||||
idx = random.randint(0, len(pair[1]) - 1)
|
||||
return pair[1][idx]
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
Reference in New Issue
Block a user