Module 1 and 2
1. A string with parentheses is well bracketed if all parentheses are matched:
every
opening bracket has a matching closing bracket and vice versa.
Write a Python function wellbracketed(s) that takes a string s containing parentheses
and returns True if s is well bracketed and False otherwise. Here are some examples
to show how your function
should work.
>>> wellbracketed("22)") should return False
>>> wellbracketed("(x+y)(x-y)") should return True
>>> wellbracketed("(x(y+z)-a)((b+c)") should return False
2. A positive integer m is a sum of squares if it can be written as k + x where k >
0, x > 0 and both k and x are perfect squares. Write a Python function
sumofsquares(m) that takes an integer m returns True if m is a sum of squares
and False otherwise. Here are some examples to show how your function
should work.
>>> sumofsquares(41) should return True
>>> sumofsquares(30) should return False
>>> sumofsquares(17) should return True
3. Write a Python function to get a string made of the first 2 and the last 2 chars
from a given string. If the string length is less than 2, return empty string,
otherwise return new string created.
4. Write a Python program to add 'ing' at the end of a given string (length should
be at least 3). If the given string already ends with 'ing' then add 'ly' instead. If
the string length of the given string is less than 3, leave it unchanged Sample
String : 'abc' Expected Result : 'abcing'
Sample String : 'string' Expected Result : 'stringly‘