**Programming Data Structures And Algorithms Using Python Assignment 2 Answers 2023:-** In This article, we have provided the answers of Programming, Data Structures And Algorithms Using Python Assignment 1 You must submit your assignment to your own knowledge.

## Programming, Data Structures And Algorithms Using Python Week 2 Quiz Assignment Answers 2023

**1. One of the following 10 statements generates an error. Which one? (Your answer should be a number between 1 and 10.)**

```
x = ["slithy",[7,10,12],2,"tove",1] # Statement 1
y = x[0:50] # Statement 2
z = y # Statement 3
w = x # Statement 4
x[0] = x[0][:5] + 'ery' # Statement 5
y[2] = 4 # Statement 6
z[4] = 42 # Statement 7
w[0][:3] = 'fea' # Statement 8
x[1][0] = 5555 # Statement 9
a = (x[4][1] == 1) # Statement 10
```

Answer:-8

**2. Consider the following lines of Python code.**

```
b = [23,44,87,100]
a = b[1:]
d = b[2:]
c = b
d[0] = 97
c[2] = 77
```

Which of the following holds at the end of this code?

- a[1] == 77, b[2] == 77, c[2] == 77, d[0] == 97
- a[1] == 87, b[2] == 87, c[2] == 77, d[0] == 97
- a[1] == 87, b[2] == 77, c[2] == 77, d[0] == 97
- a[1] == 97, b[2] == 77, c[2] == 77, d[0] == 97

Answer:-Click Here

**3. What is the value of endmsg after executing the following lines?**

```
startmsg = "python"
endmsg = ""
for i in range(1,1+len(startmsg)):
endmsg = startmsg[-i] + endmsg
```

Answer:-Click Here

**4. What is the value of mylist after the following lines are executed?**

```
def mystery(l):
l = l[1:]
return()
mylist = [7,11,13]
mystery(mylist)
```

Answer:-Click Here

## Programming Data Structures And Algorithms Using Python Assignment 2 Answers [July 2022]

**1. One of the following 10 statements generates an error. Which one? (Your answer should be a number between 1 and 10.)**

```
x = [[3,5],"mimsy",2,"borogove",1] # Statement 1
y = x[0:50] # Statement 2
z = y # Statement 3
w = x # Statement 4
x[1] = x[1][:5] + 'ery' # Statement 5
y[1] = 4 # Statement 6
w[1][:3] = 'fea' # Statement 7
z[4] = 42 # Statement 8
x[0][0] = 5555 # Statement 9
a = (x[3][1] == 1) # Statement 10
```

Answer:-7

**2. Consider the following lines of Python code.**

Which of the following holds at the end of this code?

a. a[0] == 47, b[3] == 73, c[3] == 73, d[1] == 47

b. a[0] == 65, b[3] == 105, c[3] == 73, d[1] == 95

c. a[0] == 65, b[3] == 73, c[3] == 73, d[1] == 95

d. a[0] == 95, b[3] == 73, c[3] == 73, d[1] == 95

```
b = [43,99,65,105,4]
a = b[2:]
d = b[1:]
c = b
d[1] = 95
b[2] = 47
c[3] = 73
```

Answer:-c

**Answers will be Uploaded Shortly and it will be Notified on Telegram, So JOIN NOW**

**3. What is the value of endmsg after executing the following lines?**

```
startmsg = "anaconda"
endmsg = ""
for i in range(1,1+len(startmsg)):
endmsg = endmsg + startmsg[-i]
```

Answer:-‘anaconda’

**4. What is the value of mylist after the following lines are executed?**

```
def mystery(l):
l = l[2:]
return(l)
mylist = [7,11,13,17,19,21]
mystery(mylist)
```

Answer:-[7, 11, 13, 17, 19, 21]

👇**For Week 03 Assignment Answers**👇

## Programming Data Structures And Algorithms Using Python Assignment 2 Coding Solutions July 2022

**Q1. Write a function intreverse(n) that takes as input a positive integer n and returns the integer obtained by reversing the digits in n.**

Write a function matched(s) that takes as input a string s and checks if the brackets “(” and “)” in s are matched: that is, every “(” has a matching “)” after it and every “)” has a matching “(” before it. Your function should ignore all other symbols that appear in s. Your function should return True if s has matched brackets and False if it does not.

**Write a function sumprimes(l) that takes as input a list of integers l and retuns the sum of all the prime numbers in l.**

**Code:-**

```
def intreverse(n):
ans = 0
while n > 0:
(d,n) = (n%10,n//10)
ans = 10*ans + d
return(ans)
def matched(s):
nested = 0
for i in range(0,len(s)):
if s[i] == "(":
nested = nested+1
elif s[i] == ")":
nested = nested-1
if nested < 0:
return(False)
return(nested == 0)
def factors(n):
factorlist = []
for i in range(1,n+1):
if n%i == 0:
factorlist = factorlist + [i]
return(factorlist)
def isprime(n):
return(factors(n) == [1,n])
def sumprimes(l):
sum = 0
for i in range(0,len(l)):
if isprime(l[i]):
sum = sum+l[i]
return(sum)
```

**For More NPTEL Answers:- CLICK HERE**

**Join Our Telegram:- CLICK HERE**

## About Programming Data Structure And Algorithms Using Python

This course is an introduction to programming and problem solving in Python. It does not assume any prior knowledge of programming. Using some motivating examples, the course quickly builds up basic concepts such as conditionals, loops, functions, lists, strings and tuples. It goes on to cover searching and sorting algorithms, dynamic programming and backtracking, as well as topics such as exception handling and using files. As far as data structures are concerned, the course covers Python dictionaries as well as classes and objects for defining user defined datatypes such as linked lists and binary search trees.

### COURSE LAYOUT

**Week 1**- Informal introduction to programmin, algorithms and data structures viagcd
- Downloading and installing Python
- gcd in Python: variables, operations, control flow – assignments, condition-als, loops, functions
**Week 2**- Python: types, expressions, strings, lists, tuples
- Python memory model: names, mutable and immutable values
- List operations: slices etc
- Binary search
- Inductive function denitions: numerical and structural induction
- Elementary inductive sorting: selection and insertion sort
- In-place sorting
**Week 3**- Basic algorithmic analysis: input size, asymptotic complexity, O() notation
- Arrays vs lists
- Merge sort
- Quicksort
- Stable sorting
**Week 4**- Dictionaries
- More on Python functions: optional arguments, default values
- Passing functions as arguments
- Higher order functions on lists: map, lter, list comprehension
**Week 5**- Exception handling
- Basic input/output
- Handling files
- String processing
**Week 6**- Backtracking: N Queens, recording all solutions
- Scope in Python: local, global, nonlocal names
- Nested functions
- Data structures: stack, queue
- Heaps
**Week 7**- Abstract datatypes
- Classes and objects in Python
- “Linked” lists: find, insert, delete
- Binary search trees: find, insert, delete
- Height-balanced binary search trees
**Week 8**- Effcient evaluation of recursive definitions: memoization
- Dynamic programming: examples
- Other programming languages: C and manual memory management
- Other programming paradigms: functional programming

**CRITERIA TO GET A CERTIFICATE**

Average assignment score = 25% of average of best 6 assignments out of the total 8 assignments given in the course.

Exam score = 75% of the proctored certification exam score out of 100

Final score = Average assignment score + Exam score

**YOU WILL BE ELIGIBLE FOR A CERTIFICATE ONLY IF AVERAGE ASSIGNMENT SCORE >=10/25 AND EXAM SCORE >= 30/75. If one of the 2 criteria is not met, you will not get the certificate even if the Final score >= 40/100.**

## Programming, Data Structures And Algo Using Python Assignment 2 Answers [Jan 2022]

**Q1. One of the following 10 statements generates an error. Which one? (Your answer should be a number between 1 and 10.)**

```
x = [1,"abcd",2,"efgh",[3,4]] # Statement 1
y = x[0:6] # Statement 2
z = x # Statement 3
w = y # Statement 4
x[1] = x[1][0:3] + 'd' # Statement 5
y[2] = 4 # Statement 6
z[1][1:3] = 'yzw' # Statement 7
z[0] = 0 # Statement 8
w[4][0] = 1000 # Statement 9
a = (x[4][1] == 4) # Statement 10
```

**Answer:- 7**

**Q2. Consider the following lines of Python code.**

```
x = [423,'b',37,'f']
u = x[1:]
y = u
w = x
u = u[0:]
u[1] = 53
x[2] = 47
```

**After these execute, which of the following is correct? **

(A) x[2] == 47, y[1] == 37, w[2] == 47, u[1] == 53

(B) x[2] == 47, y[1] == 53, w[2] == 47, u[1] == 53

(C) x[2] == 47, y[1] == 37, w[2] == 37, u[1] == 53

(D) x[2] == 47, y[1] == 53, w[2] == 37, u[1] == 53

**Answer:- (A) x[2] == 47, y[1] == 37, w[2] == 47, u[1] == 53 **

**Q3. What is the value of second after executing the following lines?**

```
first = "tarantula"
second = ""
for i in range(len(first)-1,-1,-1):
second = first[i] + second
```

**Answer:- ‘tarantula’**

**Q4. What is the value of list1 after the following lines are executed?**

```
def mystery(l):
l = l[0:5]
return()
list1 = [44,71,12,8,23,17,16]
mystery(list1)
```

**Answer:- [44,71,12,8,23,17,16]**

**Programming, Data Structures And Algorithms Using Python Assignment 2 Answers 2022:-** In This article, we have provided the answers of Programming, Data Structures And Algo Using Python Assignment 1 You must submit your assignment to your own knowledge.

**Disclaimer**:- We do not claim 100% surety of solutions, these solutions are based on our sole expertise, and by using posting these answers we are simply looking to help students as a reference, so we urge do your assignment on your own.

**For More NPTEL Answers:- CLICK HERE**

**Join Our Telegram:- CLICK HERE**