Joy Of Computing Using Python Week 7 Assignment 2023 September

Hey Folks, In this article answers of Joy Of Computing Using Python Week 7 Assignment 2023. I am providing these answers to the best of my knowledge. Come with us until the last to know more about the assignment. I am also providing the coding section in this page only. 

Joy Of Computing Using Python Week 7 Assignment 2023 

Joy Of Computing Using Python Week 7 Assignment 2023

Assignment 7 

Q1. Values of CSV files are separated by ?

A. Commas

B. Colons

C. Semi-colons

D. Slash

Answer: [ A ] 



Q2. What is the output of the following code?



 A. 1, 2, 3, 7, 11, 10, 9, 5, 6

 B. 1, 2, 3, 5, 6, 7, 9, 10, 11

 C. 1, 5, 9, 10, 11, 7, 3, 2, 6

 D. 1, 5, 9, 2, 6, 10, 3, 7, 11

Answer: [ C ]  1, 5, 9, 10, 11, 7, 3, 2, 6

Q3. What will be the output of the following code?

import turtle 

pen = turtle.Turtle()

for i in range(3):

      pen.forward(60)

      pen.right(120)

turtle.done() {codeBox}

A. Scalar triangle

B. Right angle triangle

C. Equilateral triangle

D. Isosceles triangle

Answer: [ C ]   Equilateral triangle



Q4. Which of the following program will draw a hexagon?

 Answer: [ C ] 


Q5. Which of the following library is used to render data on google maps?

A. gplot

B. googlemaps

C. gmplot

D. gmeplot

Answer: [ C ] gmplot

Q6. What is the output of the following code?


Q7. Which turtle command is equivalent to lifting up a pen.

 A. penlift()

 B. penup()

 C. uppen()

 D. penremove()

Answer: [ B ]  penup()

Q8. Why do we use functions?

A. To improve readability.

B. To reuse code blocks.

C. For the ease of code debugging.

D. All of the above

Answer:  [ D ]  All of the above



Q9. Library used to import images?

 A. PIL

 B. Imageview

 C. IMG

 D. image

Answer: [ A ] PIL

Q10. In snakes and ladder what can be the ways to track ladders and snakes?

A. Maintain a dictionary with snakes or ladder number blocks as keys.

B. Using the if condition to check on every number.

C. Both A and B.

D. None of the above

Answer: [ C ] Both A and B


Programming Assignment

Q1. Given a sqaure matrix M, write a function DiagCalc which calculate the sum of left and right diagonals and print it respectively.(input will be handled by us)

Input:

A matrix M 

[[1,2,3],[3,4,5],[6,7,8]] 

Output 

13

13

Explanation:

Sum of left diagonal is 1+4+8 = 13

Sum of right diagonal is 3+4+6 = 13

Program Code: 

def DiagCalc(L):

  L_sum=0

  R_sum=0

  m=L[::-1]

  for i in range(len(L)):

    for y in range(len(L)):

      if i==y:

        L_sum+=L[i][y]

        R_sum+=m[i][y] 

  print(L_sum)  

  print(R_sum,end="")  {codeBox}


Q2. Given a matrix M write a function Transpose which accepts a matrix M and return the transpose 

of M. Transpose of a matrix is a matrix in which each row is changed to a column or vice versa.

Input 

A matrix M

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

Output

Transpose of M

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

Matrix M was

1 2 3 
4 5 6
7 8 9 

After changing all rows into columns or vice versa M will become

1 4 7 
2  5 8 
3 6 9 

Program Code: 

import numpy 
from array import *
def Transpose(M):
    arrays = numpy.array(M)
    num_list = arrays.transpose().tolist()
    return(num_list) {codeBox}


Q3. Given a matrix M write a function snake that accepts a matrix M and returns a list which contain elements in snake pattern of matrix M. (See explanation to know what is snake pattern)


Program Code: 

def snake(M):
  sk=0
  sm=[]
  for r in M:
    m=[]
    sk=sk+1
    if sk%2==0:
      m=r[::-1]
    else:
      m=r
    sm+=m
  return(sm) {codeBox}

Conclusion:

If any change in the answer please visit the website on or before to the last Date. 


One Comment Please !

Post a Comment (0)
Previous Post Next Post