0% found this document useful (0 votes)
8 views1 page

Python Programming Exam Questions

Uploaded by

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

Python Programming Exam Questions

Uploaded by

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

B.

Tech(CSE/CE) 2nd Sem

End Semester Examination

FUNDAMENTALS OF INFORMATION TECHNOLOGY AND PROGRAMMING USING PYTHON


CSL-126

Note: Attempt any four questions.

Time Allowed: 2 hours Max. Marks: 100

Section A

1. (a) Explain any two output devices of computer.


(b) Draw a block diagram of computer and explain any one input device of it.
10x2=20
2. Write any five differences between the followings:
(i) RAM vs ROM
(ii) High Level Language Vs Assemble Language
(iii) Hard Disk Drive vs SSD
(iv) Complier vs Interpreter

4x5=20

Section B

3. (i) Write an algorithm and draw its flowchart to check whether a given number is prime or
not.
(ii) Write a program in python to calculate the sum of first 100 numbers which are divisible
by 20.
10x2=20
4. Explain the various data types of python with example of each.
20

Section C

5. What do you mean by recursion? What is the procedure to implement it? Justify your
answer by giving some programming example.
20
6. Write a program in python to create a module with the following functionality and access it
in an another python program :
(i) To find the sum of the list of elements
(ii) To sort a list of elements
10x2=20

Section D

7. What is the use of file handling in python? What is the use of data file? Explain the various
file operations with some examples and their syntax.
3,3,14
8. (a) Write a program in python to print only those names from a list of 50 names that
contains “eep” word.
(b) Name and explain the various modes of file handling that ate used while creating a text
and binary file with some example.
10x2=20

Common questions

Powered by AI

File handling in Python involves operations such as opening, reading, writing, and closing files, allowing programmers to manage data persistence beyond the program runtime. Python provides built-in functions such as `open()`, `read()`, `write()`, and `close()`, with different file modes like 'r' for reading, 'w' for writing, 'a' for appending, and their binary versions 'rb', 'wb', etc. File handling enables data storage and retrieval, essential for applications requiring data persistence, logging, or data manipulation. It supports handling both text and binary files, integrating methods to process file content efficiently .

RAM (Random Access Memory) is volatile memory used for storing data that is actively being worked on by the CPU, allowing for fast read and write operations crucial for efficient computing performance. In contrast, ROM (Read-Only Memory) is non-volatile and primarily used to store firmware or software that is rarely changed, such as the BIOS. The volatility of RAM means data is lost when the computer is turned off, whereas ROM retains data. This difference impacts computing performance by making RAM a critical component for running programs efficiently, while ROM is vital for system boot processes and hardware initialization .

The trade-offs between an HDD and an SSD stem from their technological differences. HDDs are traditional storage devices utilizing spinning discs to read/write data, offering larger storage capacities at lower cost but slower speeds. In contrast, SSDs use flash memory chips for data storage, providing faster data access speeds, lower power consumption, and greater durability due to the absence of moving parts. However, SSDs typically cost more per gigabyte and offer less storage capacity than HDDs. Choosing between them involves considering performance needs versus budget constraints, with SSDs favored for speed-critical applications .

An algorithm to determine if a number is prime involves checking divisibility only up to the square root of the number. If a number has no divisors other than 1 and itself, it is prime. Begin by checking divisibility from 2 to the integer value of the square root of the number; if any divisibility is found, the number is not prime. For example, using a flowchart: start -> input number -> check divisibility up to square root -> if divisible, not prime -> else, prime -> end. This utilizes the efficiency by reducing comparison operations, ensuring computational feasibility for larger numbers .

Output devices in computer systems serve the function of conveying processed data from the computer to the user in a readable form. Common output devices include monitors, which display visual data, and printers that produce hard copies of digital information. The effectiveness of an output device impacts user interaction and productivity, as they should present data clearly and efficiently. For example, high-resolution monitors allow for better visualization of graphics and text, whereas fast printers improve office workflow by quickly producing documents .

Python handles files using the `open()` function with modes such as 'r' for read, 'w' for write, 'a' for append. For binary files, similar modes apply ('rb', 'wb', 'ab'). Each mode defines the operation permitted on the file: 'r' and 'rb' open a file for reading, failing if non-existent; 'w' and 'wb' create or overwrite a file; 'a' and 'ab' append content. Handling text and binary files require careful mode selection to avoid data corruption. Examples include `file = open('filename.txt', 'r')` for reading text or `file = open('image.png', 'wb')` for writing binary data .

Recursion in programming is a technique where a function calls itself in order to solve a problem. The benefit of recursion is that it can simplify the code for problems that can be naturally divided into similar subproblems, such as computing factorials or performing fast sorting algorithms like quicksort. A recursive function typically includes a base case to end the recursive call and prevent infinite loops. For example, in computing the factorial of a number, the function calls itself with decreasing values until it reaches one: `def factorial(n): return 1 if n <= 1 else n * factorial(n-1)` .

High-level languages (HLL) like Python or Java are abstracted from machine languages and focus on productivity and ease of use, featuring strong abstraction and rich libraries which simplify complex tasks. Assembly language is low-level, providing direct correspondence to machine code instructions but lacks the portability and abstraction of HLLs, requiring detailed management of hardware specifics. These differences affect programming practices by making HLLs preferable for application development due to their readability and efficiency in coding, whereas assembly language is used in system software and performance-critical applications where control over hardware is necessary .

To create a Python module for list operations, define functions in a `.py` file, such as functions for summing list elements and sorting lists. For example: `def sum_list(lst): return sum(lst)` and `def sort_list(lst): return sorted(lst)`. This module can be imported into other Python programs using `import module_name`. Modular programming allows breaking down complex logic into smaller, manageable, reusable, and isolated units, improving code maintainability, reusability, and readability by encapsulating functionality and reducing code duplication .

Python features several data types including integers (e.g., `5`), floats for decimal numbers (e.g., `5.0`), strings for text (e.g., `'hello'`), lists for ordered collections of items (e.g., `[1, 2, 3]`), tuples for immutable ordered collections (e.g., `(1, 2, 3)`), sets for unordered collections of unique items (e.g., `{1, 2, 3}`), and dictionaries for key-value pairs (e.g., `{'key': 'value'}`). Each data type has specific uses: integers and floats for numerical computations, strings for text manipulation, lists and tuples for ordered data storage, sets for membership tests, and dictionaries for associative array-like storage .

You might also like