Question

ONE_TEN = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] Demonstrate replacing values with...

ONE_TEN = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

Demonstrate replacing values with the larger of their neighbors and demonstrate shifting to the right replacing the furthermost element with the first element in the list.
data = list(ONE_TEN)
def replaceNeighbors(data):
for i in range(len(data)):
if data[i] < data[i+1]:
data[i] == data[i+1]
replaceNeighbors(data)
print("After replacing with neighbors: ", data)

data = list(ONE_TEN)
def shiftRight(data):
data= data[-1] + dta[:-1]
shiftRight(data)
print("After shifting right: ", data)

im having trouble with these two functions can some please help me with these codes?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please let me know if anything is required. Please follow the indentation as shown in the code screenshot.

Code screenshot:

Sample output:

Copyable code: Please find the bold code for the differences between your code and written by me.

ONE_TEN = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
data = list(ONE_TEN)
def replaceNeighbors(data):
'''
as we are checking with the current element with next element then we should use len(data)-1
to avoid index out of bound exception
'''
for i in range(1,len(data)-1):
if data[i] < data[i+1]:
'''
NOTE : to assign we have to use = not ==
== means comparing
'''
data[i] = data[i+1]
return data

data=replaceNeighbors(data)

print("After replacing with neighbors: ", data)

data = list(ONE_TEN)

def shiftRight(data):
'''
we have to save the element into the other variable before assigning another value
to avoid loss of our current element value
'''
temp=data[-1]
data=data[0:len(data)-1]
data=[temp]+data
return data

data=shiftRight(data)
print("After shifting right: ", data)

Add a comment
Know the answer?
Add Answer to:
ONE_TEN = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] Demonstrate replacing values with...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Python with Pandas dataframe I have a csv file that contains a large number of columns...

    Python with Pandas dataframe I have a csv file that contains a large number of columns and rows. I need to write a script that concatenates some elements of the first row with some elements of the 2 row. Something like # if data[1][0] starts with ch then concatenate the element right below it. I have attached a picture of just a sample of my data. The booleans have to stay on there as is. But I must drop the...

  • (Please help me with Coding in Python3) AVLTree complete the following implementation of the balanced (AVL)...

    (Please help me with Coding in Python3) AVLTree complete the following implementation of the balanced (AVL) binary search tree. Note that you should not be implementing the map-based API described in the plain (unbalanced) BSTree notebook — i.e., nodes in the AVLTree will only contain a single value. class AVLTree: class Node: def __init__(self, val, left=None, right=None): self.val = val self.left = left self.right = right def rotate_right(self): n = self.left self.val, n.val = n.val, self.val self.left, n.left, self.right, n.right...

  • help finish Queue, don't think I have the right thing. # 1. After studying the Stack...

    help finish Queue, don't think I have the right thing. # 1. After studying the Stack class and testStack() functions in stack.py # complete the Queue class below (and test it with the testQueue function) # # 2. Afer studying and testing the Circle class in circle.py, # complete the Rectangle class below (and test it with the testRectangle function) # # # 3. SUBMIT THIS ONE FILE, with your updates, TO ICON. # # # NOTE: you may certainly...

  • Let U = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10), A = (1,...

    Let U = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10), A = (1, 3, 5, 7, 9), 8 (2, 4, 6, 8, 10), and C (1, 2, 3, 4, 5, 10). List the elements of each set. (Enter your answers using roster notation. Enter EMPTY or for the empty set.) (a) 4 {2, 4, 6, 8, 10) (Đ) 1 0 0 {2,4, 10) X (1) cuc {}

  • Hosted by ALEKS Corp. Homework 9 1 2 3 4 5 6 7 8 9 10...

    Hosted by ALEKS Corp. Homework 9 1 2 3 4 5 6 7 8 9 10 > Question 10 of 10 (1 point) | Attempt 1 of Unlimited | View question in a popup 11.3 Section Exercise 9 (p-value, calc) Crossover trial: A crossover trial is a type of experiment used to compare two drugs. Subjects take one drug for a period of time, then switch to the other. The responses of the subjects are then compared using matched-pair methods....

  • Accumulation Pattern Problem 2 Consider the code below. 1 2 3 4 5 6 7 8...

    Accumulation Pattern Problem 2 Consider the code below. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 labs = ['lab1', 'lab2', 'lab3', 'lab4', 'lab5', 'lab6', 'lab7', 'lab8', 'lab9'] graded = '' for lab in labs:     lab_num = int(lab[3])     if lab_num < 4:         graded = graded + lab + ' is simple\n'     elif lab_num < 7:         graded = graded + lab + ' is ok\n'     else:         graded = graded + lab + ' is complex\n'         ...

  • What is the role of polymorphism? Question options: Polymorphism allows a programmer to manipulate objects that...

    What is the role of polymorphism? Question options: Polymorphism allows a programmer to manipulate objects that share a set of tasks, even though the tasks are executed in different ways. Polymorphism allows a programmer to use a subclass object in place of a superclass object. Polymorphism allows a subclass to override a superclass method by providing a completely new implementation. Polymorphism allows a subclass to extend a superclass method by performing the superclass task plus some additional work. Assume that...

  • Journal entry worksheet 1 2 3 4 5 6 7 8 9 I established the fund...

    Journal entry worksheet 1 2 3 4 5 6 7 8 9 I established the fund by cashing a check from HHC for $280 made payable to me. Record the transaction. Note: Enter debits before credits. Transaction General Journal Debit Credit Record entry Clear entry View general journal Journal entry worksheet 1 of 2 6 7 8 9 Tom Canuck provided a $84 receipt for repairs to the club's computer, so I paid $84 cash to him. Record the transaction....

  • please answer all parts 10 9 8 7 6 5 4 3 2 1 9. I...

    please answer all parts 10 9 8 7 6 5 4 3 2 1 9. I know which countries tend to cluster in similar sociocultural and economic groupi 10 9 8 7 6 5 4 3 2 1 2. I frequently attend seminars and lectures about other cultures or international topics. 10 9 8 7 6 5 4 3 2 1 3. I believe female expatriates can be equally as effective as male expatriates. 10. I feel capable of assessing...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT