Quiz 1 Basic Programming Language
Quiz 1 Basic Programming Language
NOTE- This is a computer based exam based on the honors system -- you are not allowed to
use the internet for self-use. Submit your answer sheets transferred in a pendrive. Your folder
should be named with your Roll no and name. Anyone found not following the instructions
will be asked to leave immediately & forfeit the test marks. Submit your two answer sheets
one in .txt and one in .py format. Each of this format will contain all your answers in a
numerological order.
1) Write a Python program to search for patterns in the string below and print matched if the
pattern is found and notmatched when not found (print the pattern and matched or unmatched
in the output.) :
string = 'The quick brown fox jumps over the lazy dog.'
patterns = [ 'fox', 'dog', 'horse' ]
2) Write a Python program to search for patterns in the string below and print the location of
the pattern in the original string (print the pattern and location in the output.) :
string = 'The quick brown fox jumps over the lazy dog.'
pattern1 = 'fox'
pattern2 = 'dog'
3) Use regular expression to change the input string to the output forms given below:
Inputtext: The quick brown fox jumps over the lazy dog.
Output1: The quick brown wolf jumps over the lazy dog.
Output2: THE quick brown FOX jumps over the lazy DOG.
4) Write a Python function that matches a string that has an 'a' followed by anything, ending in
'b'. Test this on the following strings:
string1 = "aabbbbd"
string2 = "aabAbbbc"
string3 = "accddbbjjjb"
The output should clearly tell match or nomatch for each string
5) Write a Python program to find all words starting with 'a' or 'e' in a given string.
string = "Astounding aardvarks, arguably an ancient animal, always ate apples and acorns
and artichokes all around Athens, amazing. Eating enough early eases elimination."
6) Write a Python program to replace maximum 2 occurrences of space, comma, or dot with a
colon.
string = "text = 'Python Exercises, PHP exercises, C++ exercises'
7) Write a Python program to find all five characters long word in a string.
string = 'The quick brown fox jumps over the lazy dog.'
8) Write a Python program to find all words which are at least 4 characters long in a string.
string = 'The quick brown fox jumps over the lazy dog.'
9) Write a Python program to find all adverbs and their positions in a given sentence. Can you
do the same for nouns?
string = "Clearly, he has no excuse for such behavior."