Search for question
Question

CSEN 2304 Introduction to Computer Science Spring 2024 Assignment 3 This assignment consists of five individual sub-assignments that provide practical experience with the concepts and language constructs that have been covered to date (especially functions and strings). To complete the assignment you will need to write five separate Python programs that perform the tasks specified in the problem descriptions below. Make sure to include appropriate comments in your source code to document your program. Those comments should include headings at the start of your code with your name, K-number, and the date submitted. Also remember to follow the standard Python coding conventions discussed in class. Turn in your solutions by submitting a zip file that contains your five Python programs via the corresponding Blackboard system link for the assignment. This assignment focuses on creating functions to perform various string processing tasks. Remember that as discussed in class, after coding each function you should test it by invoking the function from the main program part of your Python file. Make sure to test your functions thoroughly with a wide enough range of inputs to ensure they work with all argument values they might be sent. 1. Write a Python function named swap_first_and_last( ) that receives a single string argument for processing. You can assume the string argument will have at least two characters. The function should process the string argument by swapping its first and last characters. The new string formed by exchanging the characters should be sent as a return value of the function to the calling code. So, for example, if the function is invoked with the string argument "ABCDEFG" it should send back the string "GBCDEFA" as a return value. Make sure to test your swap_first_and_last() function from the main program of your Python file to ensure it works correctly. 2. Write a Python function named remove_a_char( ) that receives two arguments: a string value "str" and an integer value “n”. The function should process the string by removing from it the character located at the index specified by the integer value. That is, it should remove from the string "str" the character located at “str[n]”. The new string formed by removing the character located at index "n" should be sent as a return value of the function to the calling code. So, for example, if the remove_a_char( ) function is invoked with the arguments "UVWXYZ" and "3" it should send back the string "UVWYZ" as a return value. Make sure to test your function from the main program of your Python file to ensure it works correctly. 3. Write a Python function named remove_odds ( ) that receives a single string argument for processing. The function should process the string by removing from it all of the characters in odd numbered index locations. The new string formed by removing the characters in odd numbered index locations should be sent as a return value to the calling code. So, for example, if the remove_odds() function is invoked with the argument "AABBCCDDEEFFGG" it should send back the string "ABCDEFG" as a return value. Make sure to test your function from the main program of your Python file to ensure it works correctly. 4. Write a Python function named reverse() that receives a single string argument for processing. The function should process the string argument by reversing the character sequence it consists of. The new string formed by reversing the character sequence should be sent as a return value of the function to the calling code. So, for example, if the reverse() function is invoked with the string argument "GFEDCBA" it should send back the string "ABCDEFG" as a return value. Make sure to test your function from the main program of your Python file to ensure it works correctly. 5. A palindrome is a sequence of characters that reads the same backwards as forwards. For example, the following words are palindromes: “kayak”, “noon”, “radar”, and “racecar". Write a Python function named is_a_palindrome() that receives a single string argument for processing. The function should process the string argument by checking to see if it is a palindrome. That is, it should check to see if the sequence of characters that makes up the string reads the same backwards as it does forwards. If the string argument is a palindrome the is_a_palindrome( ) function should return the bool value True, otherwise it should return the bool value False. Make sure to test your function from the main program of your Python file to ensure it works correctly.