Question

Write a Python program that tests the function main and the functions discussed in parts a through g.

Create the following lists:

inStock - 2D list (row size:10, column size:4)
alpha - 1D list with 20 elements.
beta - 1D list with 20 elements.
gamma = [11, 13, 15, 17]
delta = [3, 5, 2, 6, 10, 9, 7, 11, 1, 8]

a. Write the definition of the function setZero that initializes any one-dimensional list to 0 (alpha and beta).

b. Write the definition of the function inputArray that prompts the user to input 20 numbers and stores the numbers into alpha.

c. Write the definition of the function doubleArray that initializes the elements of beta to two times the corresponding elements in alpha.  

d. Write the definition of the function copyGamma that sets the elements of the first row of inStock from gamma and the remaining rows of inStock to three times the previous row of inStock.

e. Write the definition of the function copyAlphaBeta that stores alpha into the first five rows of inStock and betainto the last five rows of inStock.

f. Write the definition of the function printArray that prints any one-dimensional list. The function must contain only one loop to print any one-dimensional list.

g. Write the definition of the function setInStock that prompts the user to input the elements for the first column of inStock. The function should then set the elements in the remaining columns to two times the
corresponding element in the previous column, minus the corresponding element in delta.

OUTPUT: -The bold text is the users input. - Use tab after displaying each number. Alpha after initialization: 0 Enter 20 in

Alpha after reading 20 numbers: 1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Beta after a call to doubleArray: 4 6 10 12

Enter 10 integers: 21 22 23 24 25 26 27 28 29 30 inStock after a call to setInStock: 21 39 75 147 22 39 73 141 23 44 86 170 2

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

################### PGM START ######################################

def setZero(a):
    a=[0]*20
    print(a)
  
def doubleArray(b,a):
    for i in range(0,len(a)):
        b[i]=2*a[i]
      
def copyGamma(iS,g):
    iS[0]=g
  
    for i in range(1,10):
        for j in range(0,4):
            iS[i][j]=iS[i-1][j]*3

def copyAlphaBeta(iS,a,b):
    k=0
    for i in range(0,5):
        for j in range(0,4):
            iS[i][j]=a[k]
            k+=1
          
    k=0
    for i in range(5,10):
        for j in range(0,4):
            iS[i][j]=b[k]
            k+=1
          
def printArray(a):
    for i in range(0,len(a)):
        print(i)
      
      
def setInStock(iS,d):
  
    for i in range(0,10):
        for j in range(1,4):
            iS[i][j]=(2*iS[i][j-1])-d[i]
          
  
#main method
if __name__=="__main__":
    alpha=[0]*20
    beta=[0]*20
  
    gamma=[11,13,15,17]
    delta = [3, 5, 2, 6, 10, 9, 7, 11, 1, 8]
    inStock=[]
    for i in range(10):
        inStock.append([0] * 4)
  
  
    print("Alpha after initialization")
    setZero(alpha)

    print("Enter 20 integers:")
    for i in range(0,20):
        alpha[i]=int(input())
      
    print("Alpha after reading 20 numbers")
    print(alpha)
    print("Beta after a call to doubleArray")
    doubleArray(beta,alpha)
    print(beta)
  

    print("instock after a call to copyGamma")
    copyGamma(inStock,gamma)
    print(inStock)
  
  
    copyAlphaBeta(inStock,alpha,beta)
    print("instock after a call to copyAlphaBeta")
    print(inStock)
  
    print("\nEnter 10 integers")
    for i in range(0,10):
        inStock[i][0]=int(input())
      
      
    print("inStock after a call to setInstock")
    setInStock(inStock,delta)
    print(inStock)

###################### PGM END #########################################

OUTPUT
###########

Alpha after initialization [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] Enter 20 integers:

Alpha after reading 20 numbers [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] Beta after a call to d

Enter 10 integers inStock after a call to setInstock [[21, 39, 75, 147], [22, 39, 73, 141], [23, 44, 86, 170], [24, 42, 78, 1

Add a comment
Know the answer?
Add Answer to:
Write a Python program that tests the function main and the functions discussed in parts a...
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
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