Question: Write a function combine ( s 1 , s 2 , n ) that takes as inputs two strings s 1 and s 2 and

Write a function combine(s1, s2,n) that takes as inputs two strings s1 and s2 and an integer n, and
that returns a new string in which the first n characters of s1 are followed by the last n characters of s2.
For example:result: 'compence'
>> combine('python', 'code', 2)
result: 'pyde'
If either string (s1 or s2) does not have at least n characters, you should use all of its characters:result: 'yougram'result: 'afterfun'
Write a function reverse_last(vals,n) that takes as inputs a list vals and an integer n, and that
constructs and returns a new list in which the last n values of vals are reversed and all other values from
vals remain in their original positions. For example:
>> reverse_last ([1,2,3,4,5,6],3)
result: 1,2,3,6,5,4 # reversed the last 3 values
> reverse_last ([1,2,3,4,5,6],4)
result: 1,2,6,5,4,3 # reversed the last 4 valuesresult: [10,20,40,30] # reversed the last 2 values
If n is greater than or equal to the length of vals, the entire list should be reversed:result: [40,30,20,10]quad#6>=4, so reversed entire list
 Write a function combine(s1, s2,n) that takes as inputs two strings

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!