Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

help with these please, with explanations if you can. Thank you! 3. Write a function move_to_end (s,n) that takes as inputs a string value s

image text in transcribedhelp with these please, with explanations if you can. Thank you!

3. Write a function move_to_end (s,n) that takes as inputs a string value s and a non-negative 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) \# move 'com' after 'puter' result: 'putercom' move_to_end('computer', 5) \# move 'compu' after 'ter' result: 'tercompu' 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: move_to_end (' hi,5)#5> len(' hi ') result: 'hi' 1. Write a function Longer_len (s1,s2) that takes as inputs two string values s1 and s2, and that returns the string with the longer length. If the two strings have the same length, the function should return the first string. For example: longer_len ('computer', 'compute') result: 'computer' longer_len('hi', 'hello') result: 'hello' longer_len('begin', 'again') result: 'begin' 2. Write a function is_pal (s) that takes as input a string s and returns True if s is a pallindrome (i.e., a string like 'radar' or 'mom' that reads the same backwards as it does forward) and False otherwise. Examples: is_pal('radar') result: True is_pal('abcda') result: False Write a function repeat_elem(values, index, num_times) that takes as inputs a list values, an integer index (which you may assume is a valid index for one of the elements in values), and a positive integer num_times, and that returns a new list in which the element of values at position index has been repeated num_times times. For example: \[ \begin{array}{l} \gg \text { repeat_elem }([10,11,12,13], 2,4) \\ \text { restrtt: }[10,11,12,12,12,12,13] \end{array} \] In the above example, the second input is 2 and the third input is 4 , so we take the element at position 2 of the list (the 12) and repeat it 4 times. Other examples: repeat_elem( [10,11,12,13],2,6) \# repeat element 2 six times result: [10,11,12,12,12,12,12,12,13] repeat_elem ([5,6,7],1,3) repeat element 1 three times result: [5,6,6,6,7]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2014 Administration

Authors: Adam Jorgensen, Bradley Ball

1st Edition

111885926X, 9781118859261

More Books

Students also viewed these Databases questions

Question

LO4 Provide an overview of four challenges facing HR today.

Answered: 1 week ago