NPTEL - Joy of Computing Using Python
NPTEL - Joy of Computing Using Python
Syllabus:
Motivation for Computing, Welcome to Programming!!,Variables and Expressions : Design your own calculator,
Loops and Conditionals : Hopscotch once again, Lists, Tuples and Conditionals : Lets go on a trip, Abstraction
Everywhere : Apps in your phone, Counting Candies : Crowd to the rescue, Birthday Paradox : Find your twin,
Google Translate : Speak in any Language, Currency Converter : Count your foreign trip expenses, Monte Hall : 3
doors and a twist, Sorting : Arrange the books, Searching : Find in seconds, Substitution Cipher : What’s the secret
!!,Sentiment Analysis : Analyse your Facebook data,20 questions game : I can read your mind, Permutations :
Jumbled Words, Spot the similarities : Dobble game, Count the words : Hundreds, Thousands or Millions. Rock,
Paper and Scissor : Cheating not allowed !!,Lie detector : No lies, only TRUTH, Calculation of the Area : Don’t
measure., Six degrees of separation : Meet your favourites, Image Processing : Fun with images, Tic tac toe : Let’s
play ,Snakes and Ladders : Down the memory lane., Recursion : Tower of Hanoi, Page Rank : How Google Works
!!
MCQ WITH ANSWERS
[Link] is computational thinking important in A. Python uses braces {} for blocks
programming? B. Python is statically typed
A. It reduces the need for hardware C. Python is interpreted
B. It helps convert real-world problems into D. Python does not support functions
solvable steps 8. What will be the output?
C. It avoids the use of variables print("5" + "2")
D. It focuses only on syntax A. 7
2. Which scenario best justifies the need for B. 52
computers? C. Error
A. Writing essays D. 10
B. Performing billions of calculations accurately 9. Which of the following causes a syntax error?
C. Drawing diagrams A. x = 5 + 2
D. Printing documents B. print(x)
3. Which of the following is NOT a motivation for C. if x > 2 print(x)
computing? D. x = x * 2
A. Automation 10. Python programs are executed:
B. Speed A. Line by line
C. Accuracy B. Block by block
D. Guesswork C. All at once
4. Breaking a problem into subproblems is D. Only after compilation
known as: 11. Which variable name is INVALID in Python?
A. Abstraction A. _total
B. Pattern recognition B. total2
C. Decomposition C. 2total
D. Compilation D. total_sum
5. A computer is preferred over humans for 12. What will be the value of x?
calculations mainly because it: x = 10
A. Learns emotions x=x+5*2
B. Never makes mistakes in logic execution A. 30
C. Understands natural language B. 25
D. Works without instructions C. 20
6. What is the output? D. 15
print(type(5/2)) 13. Which operator has the highest precedence?
A. <class 'int'> A. +
B. <class 'float'> B. *
C. <class 'double'> C. **
D. Error D. /
7. Which statement about Python is TRUE? 14. What is the output?
44.
def f():
Prepared by: [Link] AP/CSE
pass while i < 5:
print(f()) if i == 3:
A. 0 break
B. False print(i, end=" ")
C. None i += 1
D. Error A. 0 1 2 3
B. 0 1 2
45. C. 0 1 2 3 4
def f(x): D. 0 1
return x+2 Explanation:
print(f(3)*f(2)) Loop stops when i == 3 before printing → prints 0 1
A. 20 2
B. 25
C. 15 2.
D. 10 for i in range(1, 6):
Explanation: if i % 2 == 0:
f(3)=5, f(2)=4 → 5×4 = 20? continue
Oops correction → 20, correct option A print(i, end=" ")
A. 1 3 5
46. Functions improve: B. 2 4
A. Code repetition C. 1 2 3 4 5
B. Memory usage D. 3 5
C. Code reuse and abstraction Explanation:
D. Execution time continue skips even numbers.
47.
def add(a,b=5): 3.
return a+b x = 10
print(add(3)) for i in range(3):
A. 3 x -= i
B. 5 print(x)
C. 8 A. 7
D. Error B. 8
48. Changing behavior via parameters is: C. 9
A. Encapsulation D. 10
B. Abstraction Explanation:
C. Parameterization i = 0,1,2 → x = 10 − (0+1+2) = 7
D. Compilation
4.
49. Apps are abstraction because: for i in range(2):
A. Show internal code for j in range(2):
B. Hide complexity if i == j:
C. Use loops print(i, j)
D. Use Python A. 0 0 1 1
B. 0 1 1 0
50. C. 0 0\n1 1
def calc(x): D. 1 1
if x%2==0: Explanation:
return x*2 Condition true only when i == j.
return x+1
5.
print(calc(5)+calc(4)) Which statement is TRUE?
A. 14 A. break skips to next iteration
B. 15 B. continue exits loop
C. 16 C. break terminates loop
D. 13 D. pass terminates program
Explanation:
calc(5)=6, calc(4)=8 → 6+8 = 14? 6.
L = [1, 2, 3]
PREVIOUS YEAR NPTEL MCQ(Loops and print(L * 2)
Conditionals : Hopscotch once again, Lists, A. [2, 4, 6]
Tuples and Conditionals : Lets go on a trip, B. [1, 2, 3, 1, 2, 3]
Abstraction Everywhere : Apps in your phone) C. Error
D. [1, 4, 9]
[Link] is the output? Explanation:
i=0 List repetition, not multiplication.
Prepared by: [Link] AP/CSE
A. (1, 2)
B. (2, 3)
7. C. (1, 2, 3)
L = [10, 20, 30] D. Error
print([Link](20))
A. 20 15.
B. 1 Which operation is NOT allowed on lists?
C. 2 A. Append
D. Error B. Delete
8. C. Slicing
T = (1, 2, 3) D. Fixed size
print(T + (4,))
A. (1, 2, 3, 4) 16.
B. (1, 2, 3) Abstraction mainly helps programmers to:
C. Error A. Write longer code
D. (4,) B. Hide internal implementation
Explanation: C. Reduce CPU speed
Tuples are immutable but can be concatenated. D. Avoid logic
17.
9. def f():
L = [1, 2, 3] return
M = [Link]() print(f())
[Link](4) A. 0
print(L) B. False
A. [1, 2, 3, 4] C. None
B. [1, 2, 3] D. Error
C. [4] 18.
D. Error def add(a, b):
Explanation: return a + b
copy() creates a new list.
print(add(2, 3))
10. A. 23
print(len([1, [2, 3], 4])) B. 5
A. 3 C. Error
B. 4 D. None
C. 5 19.
D. Error Which Python concept best represents abstraction?
Explanation: A. Loops
Nested list counts as one element. B. Variables
C. Functions
11. D. Operators
Which is TRUE about tuples?
A. Mutable 20.
B. Faster than lists def fun(x):
C. Can be modified if x > 0:
D. Can delete elements return x
12. print(fun(-3))
L = ["Goa", "Delhi", "Pune"] A. -3
print("Goa" in L) B. 0
A. True C. None
B. False D. Error
C. Error Explanation:
D. None No return for negative input → returns None.
21.
13. Apps are examples of abstraction because:
L = [1, 2, 3] A. They show algorithms
[Link](1, 5) B. They hide complexity
print(L) C. They expose hardware
A. [1, 5, 2, 3] D. They increase RAM
B. [1, 2, 5, 3] 22.
C. [5, 1, 2, 3] def f(x=5):
D. Error return x*2
14. print(f())
T = (1, 2, 3) A. 5
print(T[1:]) B. 10
Prepared by: [Link] AP/CSE
C. Error [Link] of the following is NOT an example of
D. None abstraction?
23. A. Camera app hiding sensor details
def g(x): B. Using APIs instead of writing hardware code
return x+1 C. Writing assembly code
D. Using a calculator app
print(g(g(2))) Explanation:
A. 3 Assembly code exposes hardware details instead of
B. 4 hiding them.
C. 5 Counting Candies: Crowd to the Rescue
D. Error [Link] is crowd-based counting used instead of
a single person?
24. A. To increase confusion
What is parameterization? B. To reduce individual error
A. Writing comments C. To waste time
B. Passing values to functions D. To increase cost
C. Importing modules Explanation:
D. Loop execution Multiple estimates reduce bias and error using
25. aggregation.
def calc(a, b):
return a if a > b else b [Link] many people estimate candies in a jar, the
print(calc(3, 7)) final answer is usually taken as:
A. 3 A. Maximum value
B. 7 B. Minimum value
C. True C. Average or median
D. Error D. Random value
[Link] of the following best describes Explanation:
abstraction in mobile apps? Mean or median balances out extreme guesses.
A. Writing code in Python
B. Hiding hardware details from users [Link] “wisdom of the crowd” works best when:
C. Increasing app size A. Everyone copies one answer
D. Making apps slower B. Estimates are independent
Explanation: C. Only experts participate
Abstraction hides complex implementation details D. There are very few people
(hardware, OS, network) and exposes only essential Explanation:
features to users. Independence avoids collective bias.
[Link] a map app shows only roads and [Link] computational thinking principle is
landmarks but hides GPS calculations, this is an applied when dividing a big counting task among
example of: many people?
A. Automation A. Pattern recognition
B. Decomposition B. Abstraction
C. Abstraction C. Decomposition
D. Parallelism D. Simulation
Explanation: Explanation:
Users see what the app does, not how it computes Decomposition breaks a problem into smaller tasks.
routes.
[Link] layer of abstraction directly interacts [Link] is most useful when:
with phone hardware? A. The problem has one obvious answer
A. Application layer B. The problem is subjective
B. User interface C. Individual solutions vary slightly
C. Operating system D. The task needs secrecy
D. Cloud services Explanation:
Explanation: Variation allows averaging to reduce error.
The OS acts as an abstraction layer between
hardware and applications. [Link] systems use humans to:
[Link] is abstraction essential for app A. Improve graphics
developers? B. Solve problems computers find difficult
A. To reduce app speed C. Increase server load
B. To reuse code and manage complexity D. Reduce security
C. To avoid testing Explanation:
D. To increase bugs Humans outperform computers in certain perception
Explanation: tasks.
Abstraction allows developers to build complex
systems efficiently.
[Link] a large key space, substitution ciphers are [Link] computational idea helps efficiently
weak because: generate permutations of a word?
A. Keys repeat A. Iteration only
B. Patterns remain in ciphertext B. Recursion
C. Encryption is slow C. Hashing
D. Decryption needs dictionaries D. Linear search
[Link] computational idea helps crack Explanation:
substitution ciphers efficiently? Recursive decomposition is ideal for generating
A. Random guessing permutations.
B. Pattern recognition [Link] does the number of permutations grow
C. Recursion very rapidly with word length?
D. Simulation A. Letters repeat
B. Factorial growth
[Link] analysis primarily aims to C. Linear scaling
determine: D. Randomness
A. Grammar accuracy [Link] of the following best reduces the
B. Emotional tone number of generated permutations?
C. Language structure A. Sorting the word
D. Writing style B. Removing duplicates
[Link] challenge most affects sentiment C. Increasing word length
analysis accuracy? D. Using loops
A. Font size [Link] a word with all unique letters,
B. Sarcasm and context permutations grow as:
C. Text length A. n²
D. Punctuation B. 2ⁿ
[Link] learning improves sentiment analysis C. n!
by: D. log n
A. Hard-coding rules [Link] Dobble game guarantees exactly one
B. Learning from labeled data common symbol between any two cards because
C. Ignoring context of:
D. Reducing vocabulary A. Random design
B. Graph theory
[Link] 20 Questions game works efficiently C. Finite projective planes
because it uses: D. Hash tables
A. Random guessing [Link] computational idea is primarily used
B. Linear search when identifying a common symbol quickly?
C. Binary decision trees A. Sorting
D. Brute force B. Searching
[Link] theoretical maximum number of objects C. Pattern recognition
distinguishable with 20 yes/no questions is: D. Encryption
A. 20 [Link] each card in Dobble has n symbols, the
B. 2²⁰ total number of cards possible is:
C. 20! A. n²
D. 20² B. n + 1
[Link] number of distinct permutations of the C. n² + n + 1
word BALLOON is: D. n!
A. 720 [Link] does Dobble scale poorly for very large
B. 840 symbol sets?
C. 1260 A. Memory overflow
D. 5040 B. Exponential growth
Explanation: C. Quadratic growth
BALLOON has 7 letters with L repeated twice and D. Linear increase
O repeated twice: [Link] data structure helps efficiently find
7! 5040 common elements between two sets?
= = 1260
2! 2! 4 A. List
B. Stack