Welcome to the additional basic string exercises assignment! This exercise will help you further practice working with strings in Python by implementing a few more functions. Follow the instructions below to complete the assignment.
-
Fill in the Code:
- You will complete the functions provided in the
string2.pyfile. - Each function has a description of what it should do. Your task is to write the code inside each function to achieve the described behavior.
- The
main()function is already set up to call these functions with various inputs and print'OK'when a function is correct.
- You will complete the functions provided in the
-
Function Descriptions:
- Verbing:
- Given a string, if its length is at least 3, add 'ing' to its end. Unless it already ends in 'ing', in which case add 'ly' instead. If the string length is less than 3, leave it unchanged. Return the resulting string.
- Example:
verbing('hail')should return'hailing'andverbing('swiming')should return'swimingly'.
- Not_bad:
- Given a string, find the first appearance of the substring 'not' and 'bad'. If the 'bad' follows the 'not', replace the whole 'not'...'bad' substring with 'good'. Return the resulting string.
- Example:
not_bad('This dinner is not that bad!')should return'This dinner is good!'.
- Front_back:
- Consider dividing a string into two halves. If the length is even, the front and back halves are the same length. If the length is odd, the extra char goes in the front half.
- Given 2 strings,
aandb, return a string of the forma-front + b-front + a-back + b-back. - Example:
front_back('abcde', 'xyz')should return'abcxydez'.
- Verbing:
-
Testing Your Code:
- The
main()function includes test cases that will help you verify if your implementations are correct. - The
test()function compares the output of your function with the expected result and prints'OK'if they match, otherwise it prints'X'.
- The
- Complete as many functions as you can.
- Ensure your code runs without errors.
- Submit your completed
string2.pyfile by pushing your repo to GitHub and it will auto grade.
Happy coding!