NPTEL | Programming, Data Structures And Algorithms Using Python | Week 1 : Assignment 1 Answers | July-2022

 



Week 1 Quiz

Due date: 2022-08-10, 23:59 IST.
Assignment not submitted
All questions carry equal weightage. All Python code is assumed to be executed using Python3. You may submit as many times as you like within the deadline. Your final submission will be graded.

Note:

  • If the question asks about a value of type string, remember to enclose your answer in single or double quotes.
  • If the question asks about a value of type list, remember to enclose your answer in square brackets and use commas to separate list items.

1. What does h(27993) return for the following function definition?

def h(x):
    (d,n) = (1,0)
    while d <= x:
        (d,n) = (d*3,n+1)
    return(n)
   Ans: 10



2.5 points

2. What is g(60) - g(48), given the definition of g below?

def g(n): 
    s=0
    for i in range(2,n):
        if n%i == 0:
           s = s+1
    return(s)
   Ans: 2





2.5 points
2.5 points

3. Consider the following function f.

def f(n): 
    s=0
    for i in range(1,n+1):
        if n//i == i and n%i == 0:
           s = 1
    return(s%2 == 1)

The function f(n) given above returns True for a positive number n if and only if:

 
 
 
 
2.5 points

4. Consider the following function foo.

def foo(m):
    if m == 0:
      return(0)
    else:
      return(m+foo(m-1))

Which of the following is correct?

 
 
 
 
You may submit any number of times before the due date. The final submission will be considered for grading.



No comments

File Uploading in PHP

  File Uploading in PHP PHP allow you to upload any type of a file i.e. image, binary or text files.etc..,PHP has one in built global variab...