forked from arsho/46-Simple-Python-Exercises-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem_25.py
More file actions
47 lines (41 loc) · 1.68 KB
/
problem_25.py
File metadata and controls
47 lines (41 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
'''
In English, the present participle is formed by adding the
suffix -ing to the infinite form: go -> going. A simple set
of heuristic rules can be given as follows:
a. If the verb ends in e, drop the e and add ing
(if not exception: be, see, flee, knee, etc.)
b. If the verb ends in ie, change ie to y and add ing
c. For words consisting of consonant-vowel-consonant, double the final
letter before adding ing
d. By default just add ing
Your task in this exercise is to define a function
make_ing_form()which given a verb in infinitive form
returns its present participle form. Test your function
with words such as lie, see, move and hug.
However, you must not expect such
simple rules to work for all cases
'''
import string
def make_ing_form(passed_string):
passed_string = passed_string.lower()
letter = list(string.ascii_lowercase)
vowel = ['a','e','i','o','u']
consonant = [c for c in letter if c not in vowel]
exception = ['be', 'see', 'flee', 'knee', 'lie']
if passed_string.endswith('e'):
if passed_string in exception:
return passed_string + 'ing'
else:
passed_string = passed_string[:-1]
return passed_string + 'ing'
elif passed_string.endswith('ie'):
passed_string = passed_string[:-2]
return passed_string + 'ying'
elif passed_string[-1] in consonant and passed_string[-2] in vowel and passed_string[-3] in consonant:
passed_string += passed_string[-1]
return passed_string + 'ing'
else:
return passed_string + 'ing'
verb = ['lie', 'see', 'move', 'hug', 'study']
for item in verb:
print(make_ing_form(item))