Hello again, how many problems and all of them have to google.
This time, when I wrote a text RPG, I wondered if it was possible to write such a function that could split up the entered text into words and check for a match with the basic actions (prescribed in advance), if there are 2 or more words then they are executed in order (all).
Type "pronounce a monstrous spell and drink a cool potion":
- spell
- drink a potion
Code:
sumka=['a','b','c'] def gdl (a): for e in range(len(a)): if a[e] in ("атака", "атаковать", "ударить"): return ('вы атакуете') elif a[e] in ('выпить', 'взять', 'пить', 'глотнуть', 'хлебнуть'): return ('вы пьёте') elif a[e] in ('сумка', 'портфель', 'рюкзак', 'сумку', 'с'): return (sumka) else: return ('хммм, может по-другому или что ещё') How to do it, and is it even possible?
for e in range(len(a))and so it checks in a certain order. By the way, this line is an anti-pattern and it is better to usefor e in a. - Enikeyschik