Skip to content

M.C.A. (Online Mode) Semester I Examination ​

Paper Code: OCA-501 MJ
Title: Programming from First Principles
Time: 3 Hours
Maximum Marks: 70

Q1) Multiple Choice Questions with reasoning — answer any 25 of 30 [25 × 2 = 50] ​

For every attempted question, select one option and give a brief reason.

No.QuestionABCD
1Which built-in type is immutable?listdictsettuple
2What is len({1, 1, 2})?123Error
3A higher-order function must do what?Use a loopTake or return a functionBe recursiveReturn a list
4filter(f, xs) retains items for which f returns what?A numberA stringA truthy valueNone
5In if/elif/else, how many branches execute in one pass?All true branchesAt most oneExactly twoNone always
6A list comprehension normally produces what?A generatorA listA classA function
7Why is a generator called lazy?It sorts automaticallyIt produces values on demandIt cannot be iteratedIt stores only strings
8What does yield normally do?Ends the processSuspends state and emits a valueDeletes localsImports a module
9A Python lambda may contain what?Multiple statementsOne expressionA class definitionA while statement
10Lambda abstraction means what?Naming a fileDefining a function of a variableCalling a functionDeleting a binding
11A first-class function can be what?Passed as an argumentUsed only after classStored only globallyReturned but not stored
12A closure captures variables from where?A databaseIts enclosing lexical scopeThe import cacheA type checker
13A function factory usually returns what?A configured functionA loopA moduleA syntax error
14If f = g, what does f refer to?The result of calling gThe function object gThe string "g"Nothing
15Dynamic typing associates types primarily with what?Names foreverRuntime valuesSource filesIndentation
16Type hints are normally what?Runtime enforcementMetadata for tools and readersA replacement for testsRequired everywhere
17TypeVar('T') is useful for expressing what?A fixed integerA relationship among generic typesRuntime castingFile types
18A generic identity function should use what signature idea?Unrelated Any typesThe same type variable for input and outputOnly objectNo return type
19A user-defined type is commonly created with which keyword?classyieldbreakcontinue
20An Enum is best suited to what?Arbitrary changing stringsA fixed set of named choicesMutable sequencesAnonymous functions
21Every terminating recursive solution needs what?A classA reachable base caseA global variableA generator
22Recursive calls are tracked using what?The call stackThe import pathA type tableA database
23Operational semantics describes what?Program-state changes during executionNaming conventionsFile layoutDocumentation style
24Syntax answers which question?What does it do?Is it grammatically well formed?How fast is it?Who wrote it?
25Duck typing focuses on an object's what?Declared ancestry onlySupported behaviourMemory addressFile name
26A Protocol describes what?Required operations or structureA concrete constructor onlyA loop invariantA network connection
27Polymorphism allows what?One interface to work with multiple typesVariables to have no valueClasses to store identical dataPrograms to avoid functions
28Parametric polymorphism is represented by what?Generics or type parametersOnly inheritanceGlobal variablesExceptions
29What is list(map(lambda x: x * 2, [1, 2]))?[1, 2][2, 4][2, 2]A function
30What is the conventional value of factorial(0)?01Undefined−1

Q2) Answer any five in approximately two sentences [5 × 2 = 10] ​

  1. Distinguish a list from a tuple.
  2. What is a pure function?
  3. Explain the difference between return and yield.
  4. Why are type hints useful even though Python is dynamically typed?
  5. What does @dataclass provide?
  6. State the base case and recursive case of factorial.
  7. Distinguish a protocol from a concrete class.

Q3) Answer any two in approximately ten lines [2 × 5 = 10] ​

  1. Explain higher-order functions using map, filter, and one short Python example.
  2. Compare eager list construction with lazy generator evaluation, including benefits and limitations.
  3. Trace factorial(4) recursively and explain the role of the call stack.
  4. Explain dynamic typing, strong typing, type hints, Any, and TypeVar in Python.

Built from Markdown with VitePress.