Answers for "write a python program to add 'ing' at the end of a given string"

3

write a python program to add 'ing' at the end of a given string

def str(str):
    if len(str)>=3:
        if "ing" in str:
            return f"{str}ly"
        else:
            return f"{str}ing"
    return str
            
print(str("ab"))
print(str("abc"))	
print(str("abcing"))
Posted by: Guest on April-21-2022
1

write a python program to add 'ing' at the end of a given string

#vars################
ing = "ing"
ly = "ly"
sample_str = "abc"
#vars################

find_ing = sample_str[-3:] #find the last 3 letters of a string

if len(sample_str) < 3: #if it's smaller than 3 chars'
  print("string is too small") #error message
  exit()

elif find_ing == "ing": #if it ends with ing
  sample_str = sample_str + "ly" #add ing
  print(sample_str)
else: #other situations (doesnt end with ing)
  sample_str = sample_str + "ing" #add ing
  print(sample_str)


#note: this DID take me a while and if you know how everything works, you can change it as much as you want, enjoy!
Posted by: Guest on May-18-2022
1

write a python program to add 'ing' at the end of a given string

def stringing(s): 
  ms = s.lower() # to avoid capital letters 
  if len(s)>=3:
    if ms[-3:-1]+ms[-1] !="ing": # Checking the last 3 letters of the string 
      return f"{s}ing"
    else:
      return f"{s}ly"
  else:
    return s
print(stringing("Contrast"))
print(stringing("ingress"))
print(stringing("kiNG"))
Posted by: Guest on May-11-2022

Code answers related to "write a python program to add 'ing' at the end of a given string"

Python Answers by Framework

Browse Popular Code Answers by Language