0% found this document useful (0 votes)
24 views2 pages

Python Programming Model Exam II

This document is a model exam paper for a Problem Solving and Python Programming course at RRASE College of Engineering. It includes questions divided into three parts: Part A consists of short answer questions, Part B contains detailed questions and programming tasks, and Part C focuses on specific topics like tuple operations and decision-making statements. The exam covers various programming concepts, including flow control, algorithms, data structures, and file operations.

Uploaded by

Karthika
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views2 pages

Python Programming Model Exam II

This document is a model exam paper for a Problem Solving and Python Programming course at RRASE College of Engineering. It includes questions divided into three parts: Part A consists of short answer questions, Part B contains detailed questions and programming tasks, and Part C focuses on specific topics like tuple operations and decision-making statements. The exam covers various programming concepts, including flow control, algorithms, data structures, and file operations.

Uploaded by

Karthika
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

REG.

NO

RRASE COLLEGE OF ENGINEERING


VANCHUVANCHERI, PADAPPAI.
SEM: I
MODEL EXAM II
Set-2

TIME: 3Hr
GE3151-PROBLEM SOLVING & PYTHON PROGRAMMING

PART A (10*2=20marks)

1. How does flow of control work?


2. Explain Towers of Hanoi Problem?
3. Write a snippet to display “hello world”in python interpreter?
4. Illustrate the use of * and + operators in string with example?
5. Comment with an example on the use of local& global variable with the identifier name?
6. Relate string and list?
7. Let list=[‘a’,’b’,’c’,’d’,’e’,’f’] find the following
a).list[1:3]
b) t[:4]
c) t[3:]
8. Define fruitful function?
9. How does try and execute work?
10. How do you handle the exception inside a program when you try to open a non-exixtent?
PART- B(5*13=65 marks)
11 a) (i)Compare and contrast machine language,assembly language & high level language in
detail?
ii)Give the difference between recursion and iteration?

OR

b)Explain in detail about the Notation of an algorithm?

12 a) what is the role of an interpreter?give a detailed note on python interpreter and


interactive mode of [Link] how python works in interactive mode and script mode
with examples?
OR
b)Explain in detail about Precedence of python operators and the associativity of python
operator?
13 a) Write a python program to find the square root of a number without using inbuilt
function and explain the same?
OR
b) Write a python program for linear search and binary search and explain its
implementation in detail?

14 a)Demonstrate with python code the various operations that can be performed on tuples?

OR
b)Define dictionary in python do the following operations on dictionaries
i)Initialize two dictionaries with key and value pairs.
ii)merge two dictionaries and create a new dictionary using a single expression
iii)find keys that are in first and not in second dictionary
iv)find same keys in two dictionaries

15 a)Explain about the file reading and writing operations using format operator with python
code?
OR
b)Write a python program to dump objects to a file using pickle?

PART C(1*15=15marks)
16 a)Explain in detail about tuple opearions?
OR
b)Explain in detail about Decision making statements?

Common questions

Powered by AI

An interpreter in Python translates high-level code into machine code line by line, allowing for immediate execution and debugging. In interactive mode, Python executes each line of input immediately, useful for testing and quick calculations. Script mode involves writing code in a file which is then executed in its entirety, aiding in the development of complete programs. Both modes highlight Python’s adaptability, aiding both educational and professional programming efforts.

Recursion involves functions calling themselves to solve subproblems, typically well-suited for problems like the Towers of Hanoi or Fibonacci sequence, where the problem can be divided into similar sub-tasks. Iteration, meanwhile, uses looping constructs, such as for and while loops, to repeat tasks until a condition fails. While recursion can be more intuitive and easier to implement for problems involving repeated subproblems, iteration is generally more efficient in terms of memory and performance since it avoids the overhead of multiple function calls.

A fruitful function in Python is one that returns a value after execution. This contrasts with void functions, which perform actions but do not return results. Fruitful functions are significant because they allow the integration of results from various function computations into program logic, enhancing both modularity and functionality within code structures.

The 'pickle' module allows serialization, converting Python objects into byte streams, which can be saved to files. A basic example: `import pickle; data = {'key': 'value'}; with open('data.pkl', 'wb') as f: pickle.dump(data, f)`. This process is useful as it enables data to be efficiently stored, transferred, and reconstructed, making it crucial for data persistence and transferring complex data structures between sessions or over networks.

The `+` operator concatenates strings, such as in `'Hello' + 'World'` resulting in `'HelloWorld'`. The `*` operator repeats strings, shown by `'Hello' * 3`, producing `'HelloHelloHello'`. These operators facilitate text construction and repetition efficiently in Python programming, providing essential tools for generating variations of string data.

Handling exceptions, such as using try-except blocks, is crucial when opening files to prevent program crashes. If a file doesn't exist or an incorrect path is supplied, a FileNotFoundError can be raised without proper handling. This not only disrupts user experience but may halt the processing of subsequent code. Exception handling allows developers to manage errors gracefully, offering alternative solutions or user warnings instead.

Strings in Python are immutable sequences, while lists are mutable. Both allow indexing and slicing, but only lists support element reassignment and can store different data types. Lists use square brackets (e.g., list = ['a', 'b', 'c']), while strings use quotes (e.g., string = "abc"). Operations can differ significantly; for example, `+` and `*` work for concatenation and repetition similarly in both, but modifying a part of a structure only applies to lists due to their mutability.

Flow of control in Python is determined by the sequence of execution of statements within a program. It typically involves decision-making structures like if-else statements, iterative loops like for and while, and function calls that direct the program flow. These constructs help in managing the logical flow, ensuring the correct operations and responses based on conditions and input.

Machine language is the lowest level of programming language, comprising binary instructions that computers can execute directly. Assembly language is a step higher, offering mnemonic codes and symbolic names for operations and memory addresses, which are translated into machine language by an assembler. High-level languages, like Python, abstract the complexities of the machine, using English-like syntax to enhance readability and productivity. High-level languages are interpreted or compiled, involving additional layers of translation and abstraction.

In Python, two dictionaries can be merged using the `{**d1, **d2}` syntax, where `d1` and `d2` are dictionaries. This method combines the dictionaries into a new one. If there are duplicate keys, the values from `d2` will override those from `d1`. This approach is efficient, preserves the immutability of the original dictionaries, and enhances the readability of the code by making the merge operation concise and direct.

You might also like