Strings: making HTML tags: Difference between revisions
No edit summary |
No edit summary |
||
(8 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
[[File:square.png|right|frame|This a problem set for you to work through]] | [[File:square.png|right|frame|This a problem set for you to work through <ref>http://www.flaticon.com/</ref>]] | ||
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. | 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. | ||
Line 27: | Line 27: | ||
# <i>Hello world</i> | # <i>Hello world</i> | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== Take This Farther == | |||
This simple function is very useful, and it is likely that you have used a function like this to add bold face text to a google doc. | |||
* Please create a function that creates a link. <syntaxhighlight lang="python" inline><a href="http://reddit.com/r/python">Click here</a></syntaxhighlight>. You will need the link and text to display to the user. | |||
* Add some logic which rejects [http://www.w3schools.com/tags/ref_html_dtd.asp invalid HTML tags] | |||
== How you will be assessed == | |||
Every problem set is a formative assignment. [[Media:Problem-setrubric.pdf|Please click here to see how you will be graded]] | |||
== References == | |||
<references /> | |||
== One Possible Solution == | == One Possible Solution == | ||
Line 55: | Line 70: | ||
</div> | </div> | ||
</div> | </div> | ||
[[Category:problem set]] | [[Category:problem set]] | ||
[[Category:python]] | [[Category:python]] | ||
[[Category:strings]] | [[Category:strings]] |
Latest revision as of 09:52, 17 March 2016
![](/images/d/d1/Square.png)
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 skill and knowledge of strings, specifically your knowledge and understanding of combining (concatenating) strings.
- The web is built with HTML strings like "
<i>Yay</i>
" 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 [2]
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>
Take This Farther
This simple function is very useful, and it is likely that you have used a function like this to add bold face text to a google doc.
- Please create a function that creates a link.
<a href="http://reddit.com/r/python">Click here</a>
. You will need the link and text to display to the user. - Add some logic which rejects invalid HTML tags
How you will be assessed
Every problem set is a formative assignment. Please click here to see how you will be graded
References
One Possible Solution
Click the expand link to see one possible solution, but NOT before you have tried and failed!
#
# this function returns a HTML opening and closing pair of tag
#
def make_tags(tag, word):
print("<" + tag + ">" + word + "</" + tag + ">")
return
# example input:
# make_tags('i','Hello world')
# example output:
# <i>Hello world</i>