I sent this once before but cant get it to work When I go to

I sent this once before but can\'t get it to work. When I go to run the program, what do I enter? Is it a list of numbers or what else? Please help, I am getting very discouraged with Chegg. Write list functions that carry out the following tasks for a list of integers in Intro to Python. For each function, provide a test program. Make sure to write a main a. Swap the first and last elements in the list. b. Shift all elements by one to the right and move the last element into the first position. For example, 1 4 9 16 25 would be transformed into 25 1 4 9 16. c. Replace all even elements with 0. d. Replace each element except the first and last by the larger of its two neighbors. e. Remove the middle element if the list length is odd, or the middle two elements if the length is even. f. Move all even elements to the front, otherwise preserving the order of the elements. g. Return the second-largest element in the list. h. Return true if the list is currently sorted in increasing order. i. Return true if the list contains two adjacent duplicate elements. j. Return true if the list contains duplicate elements (which need not be adjacent).

Solution

a) python program to swap first and last numbers:

begin:

read(input )//to read input

last element <- input % 10 //to get the last element

tot elements    <-   log10(input)        //total count of digits....

first element <- input / pow( 10,tot elements)      //gets the first digit

temporarynum <- last element *pow(10,tot elements) ;

temporarynum <- temporarynum + input % pow(10,tot elements) - last element ;

temporarynum <- temporarynum+firstelement ;

end

b)program to shift elements by one elemnt to right

begin

def rightshift(list)

n=len(list);

for i in range (len(list))

list = [list[-1]] + [list[ : -1]]

list

end

c)program to replce all elements with 0

begin

read(list);

for indices elements in enumerate(elements)

elements[indices] = 0;

end;

d)program to Replace each element except the first and last by the larger of its two neighbors.

import copy

def replcefirstlast(list)

n=len(list);

list1=copy.deepcopy(list);

firstelement=list[0];

lastelement=list[n-1];

for i in range (len(list))

list1=list;

if(list[i+1]>list[i-1])

{

list1[i]=list[i+1]

}

else{

list1[i]=list[i-1];

}

}

g)second largest elemnt in the list

def largest(list)

n=len(list);

lar = map(int,list.split());

maxlist=max(lar);

lar_filter=[e for e in lar if e!=maxlist]

print lar

print max(lar_filter)

h)Return true if the list is currently sorted in increasing order.

read(list1)

if(sorted(list1)== list1)

return true

else

return false;

i)Return true if the list contains two adjacent duplicate elements.

def remveadj(nums)

i=1;

while(i< len(nums))

if(nums[i]==nums[i-1])

nums.pops(i)

i=i-1

i=i+1

return nums

end

j)Return true if the list contains duplicate elements

def nodupli( list )

if(len(list) == len(set(list)))

return true;

else

false;

I sent this once before but can\'t get it to work. When I go to run the program, what do I enter? Is it a list of numbers or what else? Please help, I am gettin
I sent this once before but can\'t get it to work. When I go to run the program, what do I enter? Is it a list of numbers or what else? Please help, I am gettin
I sent this once before but can\'t get it to work. When I go to run the program, what do I enter? Is it a list of numbers or what else? Please help, I am gettin

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site