0% found this document useful (0 votes)
46 views

Strings 1) : Scan The Text and Print Out All Characters Which Are Between Square Brackets

1. Count the number of each vowel (a, e, i, o, u) in a text string and print the count for each vowel in a formatted string. 2. Scan a text and print all characters enclosed in square brackets. 3. Print the letters A-Z on one line and the letters 13 positions later in the alphabet on the next line, wrapping around from Z to A.

Uploaded by

Bollywood Cinema
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views

Strings 1) : Scan The Text and Print Out All Characters Which Are Between Square Brackets

1. Count the number of each vowel (a, e, i, o, u) in a text string and print the count for each vowel in a formatted string. 2. Scan a text and print all characters enclosed in square brackets. 3. Print the letters A-Z on one line and the letters 13 positions later in the alphabet on the next line, wrapping around from Z to A.

Uploaded by

Bollywood Cinema
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Strings

1] Count how many of each vowel (a, e, i, o, u) there are in a text string, and print the count
for each vowel with a single formatted string. Remember that vowels can be both lower and
uppercase.

2] Below is a text with several characters enclosed in square brackets [ and ].


Scan the text and print out all characters which are between square brackets.

text = """And sending tinted postcards of places they don ' t


realise they haven ' t even visited to ' All at nu[m]ber 22, weather
w[on]derful , our room is marked with an ' X ' . Wish you were here.
Food very greasy but we ' ve found a charming li[t]tle local place
hidden awa[y ]in the back streets where they serve Watney ' s Red
Barrel and cheese and onion cris[p]s and the accordionist pla[y]s
"Maybe i[t ] ' s because I ' m a Londoner " ' and spending four days on
the tarmac at Luton airport on a five -day package tour wit[h]
n[o]thing to eat but dried Watney ' s sa[n]dwiches ... """
3] Print a line of all the capital letters "A" to "Z". Below it, print a line of the letters that are 13
positions in the alphabet away from the letters that are above them. E.g., below the "A" you
print an "N", below the "B" you print an "O", etcetera. You have to consider the alphabet to be
circular, i.e., after the "Z", it loops back to the "A" again.

4] In the text below, count how often the word “wood” occurs (using pro-gram code, of
course). Capitals and lower case letters may both be used, and you have to consider that the
word “wood” should be a separate word, and not part of another word. Hint: If you did the
exercises from this chapter, you already developed a function that “cleans” a text. Combining
that function with the split() function more or less solves the problem for you.

text = """How much wood would a woodchuck chuck If a


woodchuck could chuck wood?
He would chuck , he would , as much as he could ,
And chuck as much as a woodchuck would
If a woodchuck could chuck wood."""

5] Write a program that takes a string and produces a new string that con-tains the exact
characters that the first string contains, but in order of their ASCII-codes. For instance, the
string "Hello, world!" should be turned into " !,Hdellloorw". This is relatively easy to do with list
functions, which will be introduced in a future chapter, but for now try to do it with string
manipulation functions alone.

6] Typical autocorrect functions are the following: (1) if a word starts with two capitals,
followed by a lower-case letter, the second capital is made lower case; (2) if a sentence
contains a word that is immediately followed by the same word, the second occurrence is
removed; (3) if a sentence starts with a lower-case letter, that letter is turned into a capital; (4)
if a word consists entirely of capitals, except for the first letter which is lower case, then the
case of the letters in the word is reversed; and (5) if the sentence contains the name of a day
(in English) which does not start with a capital, the first letter is turned into a capital. Write a
program that takes a sentence and makes these auto-corrections. Test it out on the string
below.

sentence = "as it turned out our aRTHUR chance meeting with REverend \ our
BElling was was to change every sunday we whole way of life , and \ St lOONY up
' d hurry along to and Jam ..." the Cream BUn \

You might also like