The Joy Of Computing Using Python Week 3 Assignment 2023

The Joy of Computing Using Python Week 3 assignment answers ? In this article we will discuss about the answers of week 3 of joy of computing. The answers shared here will be based on our own knowledge. Please use this as your reference.  

About NPTEL 

NPTEL ( National Programme on Technology Enhanced Learning). It is an online platform for providing free online courses to students and professionals in India. It is an initiative of the Ministry of Human Resource Development (MHRD), Government of India, in collaboration with seven Indian Institutes of Technology (IITs) and Indian Institute of Science (IISc). It provides high-quality and cost-effective education to students and professionals across the country. It offers courses through video lectures and interactive web-based courses. It also provides course material as PDFs, lecture slides, and practice exercises. 

The Joy Of Computing Using Python Week 3 Assignment 2023

The Joy Of Computing Using Python Week 3 Assignment 2023 

Q1. ___________  is the method to insert an item into a specified position in a list. 

a. Push 

b. Write 

c. Insert

d. All the above 

Answer: [ c ] Insert 

Q2. Which method returns the number of occurences of an element in a list. 

a. Number of 

b. Total 

c. Count 

d. Length 

Answer: [ c ]  Count 

Q3. The function random.randint(1,100) in python generates. 

a.  A random integer between 1 to 100 with 1 and 100 both inclusive.

b. A random integer between 1 to 100 with 1 and 100 both exclusive.

c.  A random integer between 1 to 100 with only 100 inclusive.

d. All the above 

Answer: [ d ] All the above 

Q4. The method open ("file.txt" , r+ ) opens the file file1.txt in ________

a. Read only mode 

b. Write only mode  

c. Read Write Mode 

d. None of the above 

Answer: [ c ] Read Write Mode

Q5. Consider the list L = { 0 , 1 , 1 , 2 , 3 , 5 , 8 , 13 , 21 , 34 } . What is the output of this code for 

       the statement  L [ 3:6] 

a. [ 2,3,5 ] 

b. [ 0,1,1 ]

c. [ 1,2,3 ]

d. none 

Answer: [ a ]  [ 2, 3, 5 ] 

 Q6. What is the output of this code ? 

           a, b = 1, 0  

           a = a^b

           b = a^b 

           a = a^b 

           print ( a ) 

a. 0 

b. 1

c. 2 

d. The code will raise a runtime error 

Answer: [ a ]   0   

Q7. What is the output of this code ? 

        def foo (l): 

              a = l [ 0 ] 

              for i in l : 

                   if i < a : 

                       a = i 

             return a 

       print ( foo ( [ 2 , 3 , 5 , 1 , 6 ]  ) )  

Answer:  1 

Q8. What is the output of this code ? 

        def bar ( string ): 

             left = 0 

             right = len (string ) 

              while ( left < right ) 

                        if ( String [ left ] != string [right ] ) 

                                   return false 

                        left += 1 

                        right -= 1 

               return True 

        print ( bar ("telugu") )

        print ( bar (" Malayalam " ) ) 

a. False  True 

b. True False 

c. True True 

d. False False 

Answer:  [ a ]  Fasle True 

Q9. Explain what will be the output of the following code when given below is executed? 

a. The program throws an error 

b. 5 

c. 5.5 

d. 4.5 

Answer: [ d ]  4.5 

Q10. Which among the following statements is True with respect the following code given below 

             Count = 0 

             for i in range (10) : 

                  for j in range ( 5): 

                        Count + = i*j 

             print (count ) 

a. count = 50 

b. The following code throws up an error 

c. count = 550 

d. count = 450 

Answer: [ d ] 450 

 

Programming Assignment  

Q1. Take an input N as an integer and write a program to display a right angle triangle with N rows and          N columns .

INPUT    5

OUTPUT 

                *
                *  * 
                *  *  *
                *  *  *  *
                *  *  *  *  * 

CODE: 

 N = int(input())
 for i in range(1,N+1):
       for j in range(1,i+1):
             print('* ',end="")
       print(){codeBox}

Q2. Write a program to take an input N and print Fibonacci sequence till N terms.

The Fibonacci sequence is a set of integers (the Fibonacci numbers) that starts with a zero, followed by a one, then by another one, and then by a series of steadily increasing numbers. The sequence follows the rule that each number is equal to the sum of the preceding two numbers.  

INPUT  7 

OUTPUT    0 
                    1
                    1
                    2
                    3
                    5 
                    8

Explanation: since the input is 7 there are seven terms. The first two terms are always 0 and 1. The third term is sum of first two terms. The fourth term is sum of second and third terms and so on.

CODE:  

N=int(input())
L=[0,1]
if N==1:
  print(0)
elif N==2:
  print(0)
  print(1)
else:  
  print(0)
  print(1)
  for i in range(N-2):
    if i==N-3:
      print(L[-1]+L[-2],end="")
    else:
      print(L[-1]+L[-2])
    L.append(L[-1]+L[-2]){codeBox}

         
Q3. Take Base B and height H as an input and write a program to print a parallelogram 

INPUT    8
                4

OUTPUT 
           
               ********
               ********
               ********
               ********

CODE:  

B=int(input())
H=int(input())
for i in range(H):
  for j in range(B):
    print('*',end="")
  if i!=H-1:  
    print() {codeBox}


Conclusion: 

Finally, these are the answers for Week 3 Assignment. Please recheck on 15 Feb for any Re-correction of answers. 

One Comment Please !

Post a Comment (0)
Previous Post Next Post