-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathproblem_24.py
More file actions
38 lines (27 loc) · 1.16 KB
/
problem_24.py
File metadata and controls
38 lines (27 loc) · 1.16 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
'''
The third person singular verb form in English is distinguished
by the suffix -s,which is added to the stem of the infinitive
form: run -> runs. A simple set of rules can be given as follows:
a. If the verb ends in y, remove it and add ies
b. If the verb ends in o, ch, s, sh, x or z, add es
c. By default just add s
Your task in this exercise is to define a function make_3sg_form()
which given a verb in infinitive form returns its third person
singular form. Test your function with words like try, brush,
run and fix. Note however that the rules must be
regarded as heuristic, in the sense that you must not expect them
to work for all cases. Tip: Check out the string method endswith()
'''
def make_3sg_form(string):
con_2 = ('o','ch','s','sh','x','z') # it's a tuple
if string.endswith('y'):
string = string[:-1]
string += 'ies'
elif string.endswith(con_2): # doesn't work on list
string += 'es' # but tuple
else:
string += 's'
return string
verbs = ['try', 'brush' ,'run', 'fix']
for item in verbs:
print(make_3sg_form(item))