Write a Python Function to Add ing at The End of a Given String And Return The New String

Given a String as an input  from the user to the program,  the Python program should  append  the three letter string  that is “ing”  to the input string and then return the final new string. This should be done using the Python function.

 

Write a Python Function to Add ing at The End of a Given String And Return The New String



Write a Python Function to Add ing at The End of a Given String And Return The New String

First let's define a function name adding  and pass the  string input argument  to the function.  once the function receives a string return string plus “ing”.  This will return the new string with added three letter character “ing”

def adding(my_string):
    return my_string + "ing"



Let's take a variable Named as text and ask a user to enter a string using input function call.  once the user enters a string so it will be stored in the variable that is text.

Now let's take another variable named as new string and call the function adding()  to add “ing”  to the end of the string and get a new string stored.

text = input("Enter a String : ")
new_string = adding(text)



Once we get a new string use the print function to print the new string  as a program output.

print("New String is : ", new_string)




Final program
=====================

def adding(my_string):
    return my_string + "ing"

text = input("Enter a String : ")
new_string = adding(text)

print("New String is : ", new_string)



Output
=====================

Enter a String : process
New String is : processing


Output
=====================

Enter a String : function
New String is : functioning



Without using a function let's try to add ING to the end of the string.  The above program can also be written as shown below. 



Final program
=====================

text = input("Enter a String : ")
new_string = text + “ing”

print("New String is : ", new_string)




Output
=====================

Enter a String : maintain
New String is : maintaining


Output
=====================

Enter a String : program
New String is : programing


Conclusion: 
Run the program by yourself and comment  down below if you got any queries o r suggestions.

Post a Comment

0 Comments