Strings: making HTML tags: Difference between revisions

From Computer Science Wiki
Line 29: Line 29:
# example output:
# example output:


# </i>Hello world</i>
# <i>Hello world</i>
</syntaxhighlight>
</syntaxhighlight>



Revision as of 11:51, 15 March 2016

This is a problem set. Some of these are easy, others are far more difficult. The purpose of these problems sets are to HELP YOU THINK THROUGH problems. The solution is at the bottom of this page, but please don't look at it until you have tried (and failed) at least three or four times.

The problem

This problem is designed to test your understanding of strings, specifically your knowledge and understanding of combining (concatenating) strings.

The web is built with HTML strings like "Yay" which draws Yay as italic text. In this example, the "i" tag makes and which surround the word "Yay". Given tag and word strings, create the HTML string with tags around the word, e.g. "Yay".
make_tags('i', 'Yay') → 'Yay'
make_tags('i', 'Hello') → 'Hello'
make_tags('cite', 'Yay') → 'Yay'

some code to get you started

#
# this function returns a HTML opening and closing pair of tag
#

def make_tags(tag, word):

    return

# example input: 

# make_tags('i','Hello world')

# example output:

# <i>Hello world</i>

one possible solution

take this farther

References