# The Joy Of Computing Using Python Week 10 : Assignment 10 | NPTEL | Answers Jan 2023

## Which math problem flames is related to?

b. Josephus problem
c. Conjecture Collatz
d. Dijkstra Problem

b. Josephus problem

## What will be the output of the following list slicing.

```s = 'The Joy of Computing'
print(s[3:12])```
a. 'Joy of C'
b. ' Joy of C'
c. 'Joy of Co'
d. ' Joy of Co'

b. ' Joy of C'

## What will be the output of the following program?

```s = 'I am amazed'
s.replace('a','z')
print(s)```
a. I zm zmzzed
b. I zm zmazed
c. I am zmzzed
d. I am amazed

d. I am amazed

This is because although the replace() method is used to replace all occurrences of the substring 'a' with the substring 'z' in the string s, the replace() method doesn't modify the original string s. Instead, it returns a new string with the replaced characters. Therefore, the original string s remains unchanged.
If you want to see the modified string, you should assign the result of the replace() method to a new variable

## What are the consequences of image compression?

a. Less size
b. Lower quality
c. More size
d. Higher quality

a. Less size
b. Lower quality

Image compression is the process of reducing the size of an image file while maintaining an acceptable level of visual quality. The consequences of image compression are a. Less size and b. Lower quality. Compressing an image reduces its size, which can make it easier to store, transmit, and share. However, compression can also reduce the quality of the image, as some information is lost during the process. The extent to which the quality is affected depends on the compression method used and the degree of compression applied.

## what is the output of the following code?

```import numpy as np
a = np.array([1,2,3,4,5,6,7,8,9,10,11,12])
print(a.reshape(3,4))

a.
[[ 1 2 3 4]
[ 5 6 7 8]
[ 9 10 11 12]]

b.
[[ 1 2 3]
[ 4 5 6]
[ 7 8 9]
[10 11 12]]

c. Error

d.
[[1,2,3,4,5,6]
[7, 8, 9, 10, 11, 12]]
```
```a.
[[ 1 2 3 4]
[ 5 6 7 8]
[ 9 10 11 12]]
```

The given code creates a NumPy array a with elements ranging from 1 to 12, and then reshapes it into a 3-by-4 array.
import numpy as np: This line imports the NumPy library and renames it as np for convenience.
a = np.array([1,2,3,4,5,6,7,8,9,10,11,12]): This line creates a NumPy array a with elements ranging from 1 to 12.
a.reshape(3,4): This line reshapes the array a into a 3-by-4 array.
The reshape method returns a new array with the same data but a different shape. The first argument specifies the number of rows and the second argument specifies the number of columns.

Support by installing "Computer Courses - All in One" android app its free

## What will be the output of the following code?

```important numpy as np

b = np.array([[1,2],[3,4]])

print(np.sum(b, axis = 1))
```
a. [4 6]
b. [3 7]
c. [3 4]
d. None of the above

b. [3 7]

## Amongst which of the following is / are the method of list?

a. append()
b. extend()
c. insert()
d. All of the mentioned above

d. All of the mentioned
above of the methods mentioned (append(), extend(), and insert()) are methods of the list data type in Python.

## The output of the following program will be?

``` word = 'Python'
word = 'n'

print(word) ```
a. Pynhon
b. Pnthon
c. Python
d. Error

d. Error
This code will result in an error because strings in Python are immutable, meaning you cannot change individual characters within a string once it has been created.

## Which of the following is not a method in string?

a. lower()
b. upper()
c. isalpha()
d. insert()

d. insert()

The lower() method returns a new string with all the characters in lowercase. The upper() method returns a new string with all the characters in uppercase. The isalpha() method returns True if all the characters in the string are alphabetic characters (letters), and False otherwise.

## What is the output of the following code?

```s = 'Hello Everyone'
print(s.lower()) ```
a. HELLO EVERYONE
b. Hello Everyone
c. helloeveryone
d. hello everyone