Answered step by step
Verified Expert Solution
Question
1 Approved Answer
***Python please: 1. Write a function named problem1 that accepts a list of integers as the argument. Then your function should remove all the odd
***Python please:
1. Write a function named problem1 that accepts a list of integers as the argument. Then your function should remove all the odd numbers from the list and sort the remaining non-odd numbers in descending order. Return the list. Call the function and display the return result. Test your function with the test case: if the input list is [1,6,4,3,7,2,5], then your function should return [6,4,2](10pts) 2. Write a function named problem 2 that accepts a string. Assume the string contains a lot of numbers that are separated by commas. Remove all the duplicates from the list, then calculate and return the sum of remaining elements. Call the function and display the return result. Test your function with this test case: if input string is "1,2,3,3,4,4,5", then your method should return 15. (10 pts) 3. Write a function named problem3 that prompts the user for a sequence of integers and appends them to a list. Each integer can appear only once in the list. You need to ask the user to re-enter a different integer if the entered integer already exists in the list. Calculate and return the sum of the list. Call the function and display the return result. You may test it with the test case: if input sequence 1 , 2,3,4,5, then your function should return 15. (10 pts) 4. Write a function named problem4 that accepts a string as the argument. Find and return the most frequent digit. You cannot use the collections module to solve this problem. Call the function with the test case and display the return result. Test case: if the given string is 'abc123cda345cc3456', your function should return 3 (only digits are considered). (10 pts) 5. Write a function named problem 5 that accepts a string and a positive integer k. Find and return a list with any k distinct characters. If k is greater than the length of the given string, return all the distinct characters. You cannot use the collections module to solve this problem. Call the function with the test case and display the return result. Test case: if the given string is 'aaabbbcccdddeeefffggg' and k=5, your function should return any five distinct characters, e.g., ['a', ' b', ' c ', 'd', 'e']. (10 pts) 6. Write a function named problem6 that accepts a string and a tag as the arguments. Assume this string contains a sequence of words that are separated by spaces. Add the tag around each word. Call the function with the test case and display the return result. Test case: if the given string is 'hello world python break' and the tag is ' # ', your function should return '\#hello\# \#world\# \#python\# \#break\#'. (10 pts)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started