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

Mid Term Exam: Python Programming 2023

This document outlines the mid-term examination for the Master of Computer Applications program at the School of Computing Science and Engineering. It includes general instructions and a series of programming questions related to Python, covering topics such as tuples, loops, string manipulation, lists, iterative structures, iteration vs recursion, and type conversions. The exam is designed to assess students' understanding and application of Python programming concepts.

Uploaded by

Andrew Tate
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)
25 views1 page

Mid Term Exam: Python Programming 2023

This document outlines the mid-term examination for the Master of Computer Applications program at the School of Computing Science and Engineering. It includes general instructions and a series of programming questions related to Python, covering topics such as tuples, loops, string manipulation, lists, iterative structures, iteration vs recursion, and type conversions. The exam is designed to assess students' understanding and application of Python programming concepts.

Uploaded by

Andrew Tate
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

ADMISSION NUMBER

School of Computing Science and Engineering


Master of Computer Applications
Mid Term Examination - Nov 2023
Duration : 90 Minutes
Max Marks : 50

Sem I - E1PA103B - Problem Solving and Computer Programming

General Instructions
Answer to the specific question asked
Draw neat, labelled diagrams wherever necessary
Approved data hand books are allowed subject to verification by the Invigilator

1) Do Python tuples and set allow for the modification of their elements K2 (2)
after creation?
2) Write a Python program that uses a for loop to find and display the K1 (3)
sum of all even numbers from 1 to 100 (inclusive).
3) Write a Python program that takes a user's input string and performs K2 (4)
the following tasks: 1. Count the number of characters (including
spaces) in the string. 2. Count the number of words in the string. 3.
Display the input string in reverse order.
4) Write a Python program to find the sum of the first n natural numbers. K2 (6)
Your program should take an integer 'n' as input and output the sum of
the first 'n' natural numbers.
5) Write a program that takes a sentence as input from the user and K3 (6)
computes the frequency of each letter. Use a variable of dictionary
type to maintain the count.
6) Explain the concept of Python lists, including how to access values in K3 (9)
lists, update list elements, and delete list elements, and provide a
program to demonstrate these operations.
7) Mention the different types of iterative structures allowed in Python. K4 (8)
Explain the use of continue and break statements with an example.

8) Briefly describe iteration and recursion. Explain with an algorithm. K4 (12)


Also, write an algorithm and draw a flowchart to calculate the net
salary of an employee.

OR
"Explain and demonstrate the concept of type conversions in Python K4 (12)
using the int(), float(), and str() functions. Provide three separate
examples, each showcasing the conversion of data from one data
type to another. In each example, include a detailed algorithm, Python
code, and the expected output. Finally, discuss the practical
significance of type conversions in programming."

Common questions

Powered by AI

Type conversions in programming allow for interoperability between different data types, ensuring that functions and operators work cohesively. In Python, they are particularly important for performing arithmetic on user input (typically strings), formatting outputs, and rendering numerical data into printable formats for reporting or debugging purposes .

Python tuples are immutable, meaning once they are created, their elements cannot be changed. In contrast, sets are mutable, allowing for modifications such as adding or removing elements after creation .

A Python program can calculate an employee's net salary by subtracting deductions (tax, insurance) from gross salary. The algorithm involves getting user inputs for gross salary and deductions, calculating the net salary, and outputting the result. The flowchart would visually represent steps: input, calculate deductions, compute net salary, and display output—a clear schematic of the logical process .

Python type conversions change data types, using functions like int() to convert strings to integers, float() to convert strings or integers to floats, and str() to convert numbers to strings. Examples include converting a string '123' to int, '45.67' to float for numerical operations, and converting an integer to a string for concatenation in outputs. Each conversion adapts data handling and operations accordingly .

A Python program can compute the frequency of each letter in a sentence by utilizing a dictionary to count occurrences. For each character in the input sentence, check if it's already a key in the dictionary. If it is, increase the count; if not, add it with an initial count of one. This efficiently tallies frequency .

Iteration relies on repetitive control structures (such as loops) to execute statements multiple times, while recursion involves a function calling itself with modified parameters. An iterative algorithm for summing numbers would use a loop, incrementing a sum variable. A recursion algorithm would involve a function calling itself with decremented parameters until a base case is reached. Each approach offers a different clarity and performance balance depending on the problem .

Type conversions in Python involve converting data from one type to another, facilitating operations that require specific data formats. Examples include 'int()' for converting strings to integers for arithmetic, 'float()' for decimal precision, and 'str()' for output formatting. These conversions ensure compatibility across different functions and operations, critical in processing diverse data inputs effectively .

Python handles string manipulation through built-in functions. Counting characters and words utilizes len() and split() functions respectively, while reversing is achieved through slicing. A program can implement these by taking input, applying these functions, and printing counts and the reversed string, demonstrating Python's versatile handling of text data .

To access a list element in Python, use its index within square brackets. Updating is done by assigning a new value to a specific index, while deletion is achieved with the del statement. A demonstration program would create a list, update an element at index 0, delete an element at index 1, and print the list after each operation to show changes .

Python supports multiple iterative structures such as for loops and while loops. The 'continue' statement skips the current iteration and proceeds to the next, while 'break' exits the loop entirely. For example, a 'for' loop iterating through a list could use 'continue' to skip processing if a certain condition is met, and 'break' to exit when a target value is found .

You might also like