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

Python Programming Exam Guidelines

This document contains instructions for a Python programming exam with 7 questions. The exam is worth a maximum of 30 marks and students must attempt any 5 questions. The questions cover topics like string slicing, searching strings in lists, tuple operations, determining if a number is positive/negative/zero, converting between Celsius and Fahrenheit, using different data types as dictionary keys, removing duplicates from lists and tuples, and creating empty sets. The instructions warn that cheating or sharing exam content could result in actions under the University's misconduct provisions.

Uploaded by

Rajesh Singh
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)
120 views1 page

Python Programming Exam Guidelines

This document contains instructions for a Python programming exam with 7 questions. The exam is worth a maximum of 30 marks and students must attempt any 5 questions. The questions cover topics like string slicing, searching strings in lists, tuple operations, determining if a number is positive/negative/zero, converting between Celsius and Fahrenheit, using different data types as dictionary keys, removing duplicates from lists and tuples, and creating empty sets. The instructions warn that cheating or sharing exam content could result in actions under the University's misconduct provisions.

Uploaded by

Rajesh Singh
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

[Link]. (Computer Science & Engineering) (Sem.

– 3)
Programming in Python
Subject Code: BTCS 510-18
Time : 2 Hrs Max. Marks : 30
INSTRUCTIONS TO CANDIDATES:
 Attempt any FIVE question(s), each question carries 6 marks.

Que 1. (a) Analyse String Slicing. Illustrate how it is done in python with Example.
(b) Write a Python code to search a string in the given list.
Que 2. Demonstrate with code the various operation that can be performed on tuples.
Que 3. Detect whether a number is positive, negative, or zero. Try using fixed
values at first, then update your program to accept numeric input from the user.
Que 4. (a) Why are variable name and type declarations not used in Python?
(b) Why are function type declarations not used in Python
Que 5. Create a pair of functions to convert Fahrenheit to Celsius temperature values. C = (F -
32) * (5 / 9) should help you get started. We recommend you try true division with this
exercise, otherwise take whatever steps are necessary to ensure accurate results.
Que 6. (a) We know that dictionary values can be arbitrary Python objects, but what about the
keys? Try using different types of objects as the key other than numbers or strings. What
worked for you and what didn't? As for the failures, why do you think they didn't
succeed?
(b) What dictionary method would we use to combine two dictionaries together?
Que 7. How will you remove all duplicates elements present in a list & tuple?

(b) Which of the following is the correct way to create an empty set?
S1=set() S2={}
What are the types of S1 & S2? How will you confirm the type?

Note:
 Any student found attempting answer sheet from any other person(s), using incriminating
material or involved in any wrong activity reported by evaluator shall be treated under
UMC provisions.
 Student found sharing the question paper(s)/answer sheet on digital media or with any
other person or any organization/institution shall also be treated under UMC.
 Any student found making any change/addition/modification in contents of scanned copy
of answer sheet and original answer sheet, shall be covered under UMC provisions.
IN Case of UMC: All MST will be Cancelled and no Internal Mark’s will be Awarded.

Common questions

Powered by AI

In Python, dictionary keys must be immutable objects since the dictionary uses hashing to store keys. Therefore, mutable objects like lists or dictionaries cannot be used as keys because their hash value can change, leading to inconsistencies in retrieving values. This immutability ensures dictionary operations remain efficient and consistent. Attempting to use mutable objects as keys results in a TypeError .

To remove duplicates while preserving order in a list, you can use a combination of a set and a list comprehension. By iterating over the list and adding elements to a set, which inherently disallows duplicates, you can track which elements have been encountered. A list comprehension that checks set membership can then be used to reconstruct the list: unique_list = [item for item in original_list if not (item in seen or seen.add(item))] where 'seen' is a set .

To combine two dictionaries in Python, the update() method is used. This method adds key-value pairs from one dictionary to another, modifying the first dictionary in place. Using update() is memory efficient and straightforward, as it seamlessly integrates new data without creating additional data structures. This approach supports rapid dictionary management in applications needing frequent merging of data .

A Python program to detect the sign of a number can use if-elif-else constructs. For fixed numbers, you define the variable directly. For user input, use input(), and convert it to an integer using int(). The structure follows: if num > 0: print('Positive'); elif num < 0: print('Negative'); else: print('Zero'). This combination allows testing both hardcoded and dynamic values, covering a range of scenarios for robust number evaluation .

Python is dynamically typed, meaning that the type of a variable is determined at runtime. This allows for more flexibility and reduces the need for declaring variable types explicitly, which can simplify code writing and reduce boilerplate. The absence of type declarations enhances Python's ease of use and readability. However, it can lead to runtime errors if incorrect data types are used, as opposed to compile-time errors .

The lack of function type declarations in Python enhances flexibility and shortens the code, making it easier to write and maintain. It allows functions to handle different data types naturally (polymorphism), which is beneficial for rapid development. However, this can lead to runtime errors if incorrect argument types are used, as the lack of compile-time checking means that errors surface only during execution. This design trade-off favors usability and flexibility over strict type safety .

Tuples in Python support several operations, including indexing, slicing, and unpacking. Indexing allows accessing specific elements, such as tuple[0] to get the first item. Slicing creates a subsequence, for example, tuple[1:3] extracts elements between indices 1 and 2. Tuples can be concatenated using the + operator and repeated using the * operator. Unpacking lets you assign each element to a variable, such as (a, b) = (1, 2). These operations highlight tuples' versatility as immutable sequences .

Accurate temperature conversion is crucial for calculations and applications that rely on precise temperature readings, such as scientific measurements and climate control systems. In Python, using true division (//) can ensure that conversion formulas like C = (F - 32) * (5 / 9) are executed accurately without truncating decimal values, which could occur if integer division were used. This precision is especially important when performing multiple calculations in sequence .

String slicing in Python allows you to access a subsequence of a string using the syntax string[start:stop:step]. The 'start' index is inclusive, while the 'stop' index is exclusive. The 'step' parameter allows for skipping characters within the defined range. For example, given the string 'hello', slicing it with string[1:4] will return 'ell' because it starts at index 1 and stops before index 4. Using string[::-1] will reverse the string .

In Python, S1 = set() creates an empty set, while S2 = {} creates an empty dictionary. Despite both seeming syntactically similar, they serve distinct purposes. You can confirm their types using the type() function: type(S1) will return <class 'set'> and type(S2) will return <class 'dict'>. This distinction highlights the importance of knowing default initializations in Python's syntax .

You might also like