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

Python Programming Assignment 2024-25

This document outlines Assignment-3 for the Python Programming course at Raj Kumar Goel Institute of Technology, detailing the course outcomes and maximum marks. It includes a list of questions that cover fundamental Python concepts such as functions, data structures, and file handling. The assignment is due on May 30, 2025, and requires students to demonstrate their understanding of various Python programming techniques.

Uploaded by

sedoy82871
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)
12 views1 page

Python Programming Assignment 2024-25

This document outlines Assignment-3 for the Python Programming course at Raj Kumar Goel Institute of Technology, detailing the course outcomes and maximum marks. It includes a list of questions that cover fundamental Python concepts such as functions, data structures, and file handling. The assignment is due on May 30, 2025, and requires students to demonstrate their understanding of various Python programming techniques.

Uploaded by

sedoy82871
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

Raj Kumar Goel Institute of Technology

Ghaziabad
ISO 9001:2015 Certified
5th KM. STONE, DELHI-MEERUT ROAD, GHAZIABAD (U.P)-201003
Tel: (0120) 2788409, Fax: (0120) 2788447
Department of Computer Science & Engineering (AI
&ML) BCC-402 Python Programming (2024-
25)
Assignment-3

Maximum Marks: 20 Submission Date: 30/05/25


Blooms
Course Outcomes Knowledge
Level
CO1 Interpret the fundamental Python syntax and semantics and be fluent in the use K1, K2
of Python control flow statements.
CO2 Express proficiency in the handling of strings and functions. K1, K2
CO3 Determine the methods to create and manipulate Python programs by K3
utilizing the data structures like lists, dictionaries, tuples and sets.
CO4 Identify the commonly used operations involving file systems and regular K1, K2
expressions.
CO5 Articulate the Object-Oriented Programming concepts such as encapsulation, K2, K3
inheritance and polymorphism as used in Python.

ATTEMPT ALL QUESTIONS

1. What is the difference between a function and a method in Python?


2. Explain the concept of function arguments and parameters in Python.
3. What are the different ways to define and call a function in Python?
4. Create a Python function that accepts a string and returns the reverse of that string.
5. Implement a Python function that takes a list of integers and returns a new list containing the squares of
each number.
6. Write a Python program using lambda and map.
7. Write a Python program, which returns a list with 2-tuples. Each tuple consists of the order number and
the product of the price per item and the quantity. The product should be increased by 10, - € if the
value of the order is smaller than 100,00 €.
8. Use a lambda function in Python to sort a list of tuples based on the second element of each tuple.
9. Write a program to create three dictionaries and concatenate them to create a fourth dictionary.
10. Write a program to sort a dictionary in ascending and descending order by key and value.
11. Explain the difference between 'append' and 'extend' in Python?
12. Write a python program to count the vowels present in a given input string.

Common questions

Powered by AI

Dictionaries in Python use hash tables to store key-value pairs, which makes data retrieval operations like lookups, inserts, and deletions average O(1) time complexity. This efficiency significantly affects application performance positively, especially in applications requiring frequent read/write operations, such as database management systems or web services. However, this efficiency depends on the quality of the hashing function, and issues like hash collisions can degrade performance. Python's implementation optimizes for space and speed, but developers must manage keys appropriately to maintain key uniqueness and data integrity.

Using lambda functions for sorting in Python is particularly powerful due to their ability to provide inline, concise expressions for key extraction. For example, when sorting a list of tuples based on the second element, a lambda function can be used with the 'sort' method or 'sorted' function, making the operation concise and expressively clear. This use of lambda increases readability and reduces boilerplate code, especially when complex criteria are needed for sorting. However, it can impact performance in memory-intensive operations due to lambda's non-reusability, and debugging can be challenging due to their anonymous nature.

In Python, a function is defined using the 'def' keyword and can exist independently, while a method is a function that is associated with an object. Methods are called on objects and may have access to the object instance through the 'self' parameter, which allows modification of object attributes. This distinction impacts programming practices by encouraging encapsulation and reusability of code, as classes with methods can more intuitively model real-world objects and actions, leading to cleaner and more organized code structures.

Python provides robust string handling capabilities including built-in methods such as slicing, concatenation, and formatting. Unlike some languages that treat strings as character arrays, Python treats strings as objects with methods, which offers higher-level abstractions for string manipulations. The immutability of strings in Python ensures that any modification results in creation of a new string, preserving data consistency. Python also integrates support for advanced string operations like regular expressions, facilitating complex pattern matching and text processing. This high-level, object-oriented approach allows Python to offer more readable and concise code, especially for text-heavy applications.

Effective strategies for counting vowels in strings using Python include using loops to iterate over each character, using the 'count' method on lowercased or uppercased versions of the string, and employing a dictionary to tally occurrences. A more efficient method involves using collections like 'Counter' from the 'collections' module, which automates counting and offers optimized performance for larger datasets. While basic looping is sufficient for small strings, 'Counter' performs better for large-scale text processing due to its use of hash maps internally. This comparison highlights the importance of choosing the right tools based on data scale and operation complexity.

The 'append' method in Python adds a single element to the end of a list, whereas 'extend' adds multiple elements from an iterable (like a list or a tuple) to the end of a list. The use case for 'append' is when you need to add a single item, such as a new record. 'extend' is beneficial when you need to combine multiple collections into one list, effectively merging datasets. This distinction is crucial in scenarios requiring list mutations without unnecessarily increasing complexity or processing time through repeated element appends.

Python functions can be defined using 'def', optionally with parameters and a return statement. They can be invoked by calling with or without arguments, which may include positional, keyword, default, and variable-length arguments. Anonymous functions can be created using 'lambda'. This variety in defining and invoking provides flexibility in function design, supporting a range of use-cases from simple utility functions to complex, data-driven operations. These methods facilitate functional programming paradigms within Python and allow for concise, higher-order function operations through tools like 'map', 'filter', and 'reduce'.

Python implements object-oriented concepts such as encapsulation, inheritance, and polymorphism to manage and reuse code. Encapsulation is achieved through the use of classes where internal details of data are hidden and controlled through accessors and mutators. Inheritance in Python allows classes to derive properties from existing classes, using a simple syntax that supports multiple inheritance, unlike languages such as Java. Polymorphism in Python is handled through method overriding and duck typing, which emphasizes behavior over explicit interface declarations. This makes Python's approach to polymorphism distinct, as it relies on an object's abilities rather than its class or inheritance hierarchy, allowing for more flexible and dynamic executions compared to statically typed languages like C++.

Python handles file operations with built-in functions like 'open', 'write', and 'read', using file objects to manage files contextually. Its standard library provides the 'os' and 'shutil' modules for more complex file system operations. Regular expressions are managed using the 're' module, which allows for flexible pattern matching. Common challenges include correctly managing file paths and file handles to prevent data corruption or leaks, and the complexity of designing correct regular expressions, which can result in hard-to-maintain code if not properly commented or structured. Despite these challenges, Python's built-in capabilities make it highly effective for text processing and file manipulation.

Python provides several built-in data structures such as lists, dictionaries, tuples, and sets, each serving different purposes. Lists are ordered, mutable collections of items, suitable for sequences of elements. Dictionaries are unordered collections of key-value pairs optimized for fast retrieval, making them suitable for associative arrays. Tuples are ordered, immutable sequences and are used for fixed data collections. Sets are unordered, mutable collections of unique elements, ideal for membership testing and eliminating duplicates. These diverse structures allow engineers to choose the appropriate structure based on the need for mutability, order, and uniqueness in data handling, often leading to better optimized and more resilient code.

You might also like