Sunday, 3 June 2018

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. Sample String : 'abc' Expected Result : 'abcing' Sample String : 'string' Expected Result : 'stringly'

#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.
#   Sample String : 'abc'
#   Expected Result : 'abcing'
#   Sample String : 'string'
# Expected Result : 'stringly'

def isConSpace(s):
    for n in s:
        if n == " ":
            return True
    return False
str = input("Enter a string : ")

if(len(str)>0):
    if(isConSpace(str)==False):
        if(str.isalpha()):
            if(len(str)>2):
                if(str[-3:] == "ing"):
                    str+=("ly")
                    print(str)
                else:
                    str+=("ing")
                    print(str)
            else:
                print(str)
        else:
            print("String must be contain only alphabet.")
    else:
        print("Please enter a string without space.")
else:
    print("String is empty.")

input("Press Enter to exit.")

No comments:

Post a Comment

Featured post

In all other cases the driver is not insured. If the marital status, sex and age of the driver are the inputs, write a program to determine whether the driver is to be insured or not.

  #include #include int main() { char ms;   printf("Is Driver married (Y/N): ");  scanf("%c",&ms);   if(ms=='y&#...

Popular Posts