Question: Although this function could be completed in one line, you must use the following template: def first_and_last(values): put your docstring here first = last =

 Although this function could be completed in one line, you mustuse the following template: def first_and_last(values): put your docstring here" first =

Although this function could be completed in one line, you must use the following template: def first_and_last(values): put your docstring here" first = last = return [first, last] Here are some examples of how the function should work: >>> first_and_last([1, 2, 3, 4]) result: [1, 4] # 7 is both first and last! >>> first_and_last([7]) result: [7, 7] >>> first_and_last(['how', result: ['how', 'you?'] 'are', 'you?']) Warning Remember that your functions should return the correct value rather than printing it. If your function is printing the return value, you won't see an output prompt (the result: prompt above) before the return values. If you don't see that prompt, you must fix your function so that it uses a return statement rather than a print statement. This same warning applies to all of the functions that you will write for this assignment, with the exception of the optional test functions that you may include for testing your code. 2. Write a function even_odd(s) that takes as input a string s and returns a new string in which all of the characters that are in even positions (0, 2, 4, etc.) in the original string are followed by all characters in odd positions (1, 3, 5, etc.). >>> even_odd'abcdefg') 2. Write a function even_odd(s) that takes as input a string s and returns a new string in which all of the characters that are in even positions (0, 2, 4, etc.) in the original string are followed by all characters in odd positions (1, 3, 5, etc.). >>> even_odd('abcdefg') result: 'acegbdf' >>> even_odd('programming') result: 'pormigrgamn' Hint: Use skip-slicing twice! 3. Write a function move_to_end(s, n) that takes as inputs a string value s and an integer n, and that returns the a new string in which the first n characters of s have been moved to the end of the string. For example: >>> move_to_end('computer', 3) result: 'putercom' # move 'com' after 'puter' >>> move_to_end('computer', 5) result: 'tercompu # move 'compu' after 'ter' >>> move_to_end('computer', 0) result: 'computer' Special case: If n (the second input) is greater than or equal to the length of s (the first input), then the function should simply return the original s without changing it: # 5 > len('hi') >>> move_to_end('hi', 5) result: 'hi' Don't forget to test your functions using the approaches mentioned at the start of Problem 3. You may also find it helpful to use Python Tutor Visualizer to trace through the execution of your functions, as described at the end of Problem 3

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!