Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, I need help to add two more functions to the following code in python: 1. extend( otherVector ): Extends this vector by appending the

Hello, I need help to add two more functions to the following code in python:

1. extend( otherVector ): Extends this vector by appending the entire contents of the otherVector to this vector.

2. subVector( from, to ): Creates and returns a new vector that contains a subsequence of the items in the vector between and including those indicated by the given from and to positions. Both of the from and to positions must be within the valid range.

import array as arr

class vector:

def __init__(self):

self.items=arr.array('i',[0,0])

def length(self):

return (len(self.items))

def contains(self,item):

if item in self.items:

print('found')

else:

print('not found')

def getitem(self,item):

return (self.items[item])

def setitem(self,item):

print (self.items.insert(1, item))

def append (self,item):

print(self.items.append(item))

def insert(self,item):

print (self.items.insert(4, item))

def remove(self):

return self.items.pop(1)

def indexof(self,item):

print (self.items.index(item))

v=vector()

print(v.items)

print(v.length())

print(v.contains(0))

print(v.getitem(1))

print(v.setitem(1))

print(v.items)

print(v.append(3))

print(v.items)

print(v.insert(7))

print(v.items)

print(v.remove())

print(v.items)

print(v.indexof(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_2

Step: 3

blur-text-image_3

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

Databases On The Web Designing And Programming For Network Access

Authors: Patricia Ju

1st Edition

1558515100, 978-1558515109

More Books

Students also viewed these Databases questions

Question

1. Explain the concept of diversity and equality in the workplace.

Answered: 1 week ago

Question

=+ 2. What is the opportunity cost of seeing a movie?

Answered: 1 week ago

Question

=+ what roles should government play in them ?

Answered: 1 week ago

Question

=+ Why do we have markets and, according to economists,

Answered: 1 week ago