### The Joy of Computing using Python | Week 2

Session Jan-Apr 2023

Course Name:  The Joy of Computing using Python

These are answers of The Joy of Computing using Python Assignment 2 Answers

#### Q1. What are the applications of Python?a. Image processing and graphic design applicationsb. Enterprise and business applications developmentc. Operating systemsd. All of the abovee. None of the above

Answer: d. All of the above

Q2. Which of the following is not the correct variable name
a. Abc
b. Abd23
c. 32asd
d. Ab_cd_23

Q3. Write the output of the following code.
L = [1,2,3,4,5,6,7,8,9]
print(L[::-1])

a. [1,2,3,4,5,6,7,8,9]
b. [1,2,3,4,5,9,8,7,6]
c. [9,8,7,6,5,4,3,2,1]
d. Error

These are answers of The Joy of Computing using Python Assignment 2 Answers

Q4. Predict the output of the following code:
L = [[1,2,3],[0,4,5],[0,0,6]]

a. 3,2,1,5,4,6
b. 3 2 1 5 4 6
c. 0,0,0,0,0,0
d. 0 0 0 0 0 0

Answer: b. 3 2 1 5 4 6

Q5. Find all the error(s)in the following code:

a. Index out of range
b. Syntax error
c. Variable not defined
d. ‘int’ object does not support item assignment

Q6. What is the output of the following code:

a. [0,1,2] (5,3,4)
b. [0,1,2] (5,)
c.  (5,3,4)
d.  (5,)

These are answers of The Joy of Computing using Python Assignment 2 Answers

Q7. What is the correct syntax for defining a function in Python?
a. def function name():
b. function function_name():
c. function_name():
d. def function_name:

Q8. What is the purpose of the continue statement in a for loop?
a. To skip the rest of the current iteration and move on to the next one
b. To terminate the loop and exit the loop block
c. To return to the top of the loop and start a new iteration
d. To skip the current iteration and move on to the next one, but only if a certain condition is met

Answer: a. To skip the rest of the current iteration and move on to the next one

Q9. How do you check if a number is even in Python?
a. if number % 2 == 0
b. if number.is_even()
c. if number % 2 is 0
d. if number.even()

Answer: a. if number % 2 == 0

These are answers of The Joy of Computing using Python Assignment 2 Answers

Q10. What should be the value of _ to print all numbers from 0-10?

a. 11
b. 9
c. 10
d. None of the above

### The Joy of Computing using Python Programming Assignmnet

Question 1

Given an integer as an input, write a program to print that integer.
Input
A number
Output
A number

Solution:

``````print(num)
``````

These are answers of The Joy of Computing using Python Assignment 2 Answers

Question 2

Given two integers as an input, write a program to print the sum of those two integers.

Solution:

``````print(num1 + num2)
``````

These are answers of The Joy of Computing using Python Assignment 2 Answers

Question 3

You are given a number as an input. You have to display all the numbers from 0 till x.
Input
x
Output
0
1
2
.
.
x

Solution:

``````for i in range(num+1):
print(i)``````

These are answers of The Joy of Computing using Python Assignment 2 Answers

More Nptel courses: https://progiez.com/nptel/

Session JUL-DEC 2022

#### These are answers of The Joy of Computing using Python Assignment 2 Answers

Q1. What is the correct command to show the value stored in a variable?

a) show()
b) cout()
c) print()
d) out()

Ans:- c

Q2. What will be the output of the following piece of code?

a)Hello Mr. Bond 34
b) Hello Mr. 34
c) Hello Mr. Bond 35
d) Hello Mr. Bond 34

Ans:- c

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

a) 10,10
b)10
c)no output
d)error

Ans:- d

These are answers of The Joy of Computing using Python Assignment 2 Answers

Q4. What is the extension of a python file?

a) sc
b) py
c) md
d)cp

Ans:- b

Q5. what will be the output of the following code, if the given input is 5?

A = input()

print(A*5)

a)25
b)55555
c)55
d)5

Ans:- b

These are answers of The Joy of Computing using Python Assignment 2 Answers

Q6. Which of the following commands are correct to take input from a user?
a) n = input(‘Hello’)
b) n = input(“42”)
c) n = input(‘42’)
d) n = input(Hello)

e) n= input()

Ans:- a,b,c,e

Q7. What will be the output of the following code if the input is ‘5’?
a)25

b)25.0
c) Error
d) 5555

Ans:- a

These are answers of The Joy of Computing using Python Assignment 2 Answers

Q8. Which of the following blocks of codes are correct?(Assume x and y are initialized)

Ans:- b

Q9. Which of the following statements are correct regarding the following code?

Ans:- Update Soon…

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

Ans:- b

## The joy of computing using python coding Assignment NPTEL

Q1. Write a program to take an input from the user and print that input.

``````string = input()
print(string, end="")``````

Q2. Write a program to take an input of two numbers A, and B and print the difference A-B

Code:-

``````A = int(input())
B = int(input())

z = A-B

print(z, end="")``````

Q3. Take a string S and an integer A as an input from a user. Write a program to print string S, A number of times.

Code:-

``````S = input()
A = int(input())

for i in range(1,A+1):
print(S)``````

These are answers of The Joy of Computing using Python Assignment 2 Answers

* The material and content uploaded on this website are for general information and reference purposes only. Please do it by your own first. COPYING MATERIALS IS STRICTLY PROHIBITED.