Home / Programs / Python Decorators - 5 - Hands On
🚀 Programming Example

Python Decorators - 5 - Hands On

👁 537 Views
💻 Practical Program
📘 Step Learning

Python Decorators - 5 - Hands On

📌 Information & Algorithm

5. Decorators - 5

1. Define a function greet which accepts a string and returns italic HTML tags.

2. Use the Test against custom input box to output the result for debugging.

3. Provide a string (refer test case samples) to display the output/error.

Input:

Hello World! Welcome to Python Programming Language

Output:

Hello World! Welcome to Python Programming Language

Given Input:

Hello World! Welcome to Python Programming Language

Expected Output:

 
<i>Hello World! Welcome to Python Programming Language</i>

💻 Program Code

import os

import sys


def bold_tag(func):

    

    def inner(*args, **kwdargs):

        return '<b>'+func(*args, **kwdargs)+'</b>'

        

    return inner


def italic_tag(func):

    

    def inner(*args, **kwdargs):

        return '<i>'+func(*args, **kwdargs)+'</i>'

        

    return inner

    

#Add greet() function definition

@italic_tag

def greet():

    msg=input()

    return msg

    

'''Check the Tail section for input/output'''

if __name__ == "__main__":
    with open(os.environ['OUTPUT_PATH'], 'w') as fout:
        res_lst = list()
        res_lst.append(greet())
        fout.write("{}".format(*res_lst))
                        

🖥 Program Output

<pre class="prettyprint"> <xmp>
<i>Hello World! Welcome to Python Programming Language</i>
</xmp></pre>
                            
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.