Q:

Write a Python program to add /ing/ at the end of a given string (length should be at least 3

0

Write a Python program to add "ing" at the end of a given string (length should be at least 3). If the given string already ends with "ing" then add "ly" instead. If the string length of the given string is less than 3, leave it unchanged

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

def add_string(str1):
  length = len(str1)

  if length > 2:
    if str1[-3:] == 'ing':
      str1 += 'ly'
    else:
      str1 += 'ing'

  return str1
print(add_string('ab'))
print(add_string('abc'))
print(add_string('string'))

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now