The Joy of Computing Using Python | Week 2

Session: JULY-DEC 2023

Course Name:  The Joy of Computing using Python

Course Link: Click Here

These are the Joy of Computing using Python Assignment 2 Answers


Q1. Which of the following is a high-level programming language?
Assembly
C
Python
Machine Language

Answer: Python


Q2. Which of the following is an example of a front-end programming language?
PHP
Java
HTML
SQL

Answer: HTML


Q3. Which of the following is used to store data in a programming language?
Variables
Arrays
Loops
Conditionals

Answer: a, b


These are the Joy of Computing using Python Assignment 2 Answers


Q4. Which statement will print ‘The joy of computing’?
print(The joy of computing)
print The joy of computing
printf(‘The joy of computing’)
print(‘The joy of computing’)

Answer: print(‘The joy of computing’)


Q5. What should be the value of _ to print all numbers from 0-10
10
9
11
None of the above

Answer: 11


Q6. Which of the following keyword is used to declare a function in a programming language?
def
var
int
float

Answer: def


These are the Joy of Computing using Python Assignment 2 Answers


Q7. What will be the output of the following code?
0
45
43
50

Answer: 45


Q8. What value will c store in it after the execution of the below code?
c=b**3

Value of b multiplied by 3
Cube of b
Value of b multiplied with 3 twice
It will throw an error

Answer: Cube of b


Q9. What will be the output? suppose the input is 30
60
Error
3030
30

Answer: 3030


These are the Joy of Computing using Python Assignment 2 Answers


Q10. What is the output for the following program?
True
False
It will display an error message
Boolean

Answer: False


These are the Joy of Computing using Python Assignment 2 Answers

More Weeks of The Joy of Computing Using Python: Click here

More Nptel Courses: Click here


Session Jan-Apr 2023

Course Name:  The Joy of Computing using Python

Course Link: Click Here

These are the Joy of Computing using Python Assignment 2 Answers


Q1. What are the applications of Python?
a. Image processing and graphic design applications
b. Enterprise and business applications development
c. Operating systems
d. All of the above
e. 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

Answer: c. 32asd


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

Answer: c. [9,8,7,6,5,4,3,2,1]


These are 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]]

image

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:

image 1

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

Answer: a, b


Q6. What is the output of the following code:

image 2

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

Answer: b. [0,1,2] (5,)


These are 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:

Answer: a. 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 the Joy of Computing using Python Assignment 2 Answers


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

image 3

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

Answer: a. 11


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 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 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 the Joy of Computing using Python Assignment 2 Answers

More Weeks of The Joy of Computing using Python: Click Here

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


Session JUL-DEC 2022

These are 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 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 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 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 the Joy of Computing using Python Assignment 2 Answers

The Joy of Computing using Python Assignment 2 Answers

This content is uploaded for study, general information, and reference purpose only.