How to add 'ing' at the end of a given string or 'ly' if the given string already ends with 'ing' in Python

1 Answer

0 votes
def add_ing_or_ly(str):
  if len(str) >= 3:
    if str.endswith("ing"):
      str += "ly"
    else:
      str += "ing"

  return str
  
  
print(add_ing_or_ly('python'))
print(add_ing_or_ly('xyz'))
print(add_ing_or_ly('ab'))
print(add_ing_or_ly('ping'))


 
 
'''
run:
 
pythoning
xyzing
ab
pingly
 
'''

 



answered Aug 30, 2021 by avibootz

Related questions

2 answers 201 views
1 answer 193 views
1 answer 189 views
1 answer 125 views
1 answer 141 views
...