0% found this document useful (0 votes)
20 views3 pages

Python Application Programming-18EC646

The document outlines a series of programming questions and tasks related to Python, divided into five modules. Each module contains various questions that cover topics such as error handling, functions, loops, string manipulation, file handling, classes, and database operations. Students are instructed to answer five full questions, selecting one from each module.

Uploaded by

Krish
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)
20 views3 pages

Python Application Programming-18EC646

The document outlines a series of programming questions and tasks related to Python, divided into five modules. Each module contains various questions that cover topics such as error handling, functions, loops, string manipulation, file handling, classes, and database operations. Students are instructed to answer five full questions, selecting one from each module.

Uploaded by

Krish
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

Note: Answer any FIVE full questions, choosing ONE full question from each module.

Module-l
1 a. Explain building blocks of the python program. (06 Marks)

-g b. Identify and explain different general types of errors encountered in the python program .
.~ Write a python program which prompts the user for a Celsius temperature, convert the
~,.g temperature to Fahrenheit and print the converted temperature. (06 Marks)
C'O:::::
~~
.§ :;:f c. Illustrate catching exception using try and except with syntax.
~ 11 Write a program to prompt for a score between 0.0 and 1.0. [If the score is out of range, print
.~ ~ an error. If the score is between 0.0 and 1.0 print a grade using the following table:
E ci)
~ u
Score Grade
..t:
-U t:
u
:::
c ·c
>=0.9
>= 0.8
A
B
o :s
~ 1:3 >= 0.7 C
:'::2
V>
V>
'0;
;J
>= 0.6 D
-
b 8"
I-
< 0.6 F
t:--
'" 0 (08 Marks)
0"0
00 t:

~'" '"~ o~
:s ~
f::..2
"0 '"
2 a. Explain the following :
.b~ (i) Skills necessary for programmer
·c 0
o -
v>_ (ii) Interpreter and compiler
:=i0.0.
i'3
(iii) Short circuit evaluation of the expression
E 0.
o '" (iv) Modulus operator (08 Marks)
~g
I- .-

~ ~
v>t.:: b. Compare fruitful and void function with example. (04 Marks)
@ .~
•.. u
g~ c. Write a python program to reverse a number and find the sum of digits' of the reversed
;>. "-
00°
·c c
t: 00 number using function. Prompt the user for inputs. (08 Marks)
u:.::
~~
E ~ Module-2
°
U
I-
;>.
t: t: 3 a. Illustrate the important parameters involved in the loop construction and explain the working

....;r-i ofthe infinite and definite loop with example. (06 Marks)
Q)

(5
z b. Mention the advantages of the continue statement. Write a python program to compute only
-
@
t
even numbers sum within the natural numbers using continue statement. (06 Marks)

°
0.

E c. Write a program to count the total number of vowels, consonants and blanks in the given
string. String = "May God Bless You". (08 Marks)

1 on
18EC646
OR
4 a. Explain string slice and strings are immutable with syntax. (04 Marks)

b. Identify and explain different file methods associated with file object along with syntax.
(10 Marks)

c. Write python program to find the longest word in a file. Get the file name from the user
(06 Marks)

Module-3
5 a. Explain list operations with example. Write a python program to add two 3 x3 matrices
using list. (08 Marks)

b. Differentiate the following with syntax:


(i) pop() and remove( )
(ii) sort() and reverse( )
(iii) append( ) and insert( ) (06 Marks)

c. Write a python program to count the number of characters in the string using dictionaries.
Display the keys and their values in alphabetic order. (06 Marks)

OR
6 a. Illustrate the relation between tuples and lists with example. (06 Marks)

b. Write python program using tuples to swap two numbers without usmg intermediate
variables. Prompt the user for input. (04 Marks)

c. Write a python program to check the validity of a password. The password should contain at
least (i) one lower case letter (ii) one digit (iii) one upper case letter (iv) one special
character [$, @, #,!] (v) Six characters long. The program should accept a password and
check the validity of the password using the above criteria and print "Valid" and "Invalid"
as the case may be. (10 Marks)

Module-4
7 a. Explain the creation of classes and objects in python language with syntax. (OS Marks)

b. Explain copying an object in python with example. (OS Marks)

c. Write a python program using class and object concept to deposit, enquire and withdraw
money in a Bank Account. (10 Marks)

OR
8 a. Explain pure and modifier method with example. (OS Marks)

b. Explain _init_() method and _str_() method with example. (OS Marks)

c. Write python program to create TIME class to present the time III HH:MM :SS format.
Perform the following operations:
(i) Create T], T2, T 3 TIME objects
(ii) Initialize T], T2, T3 using _init_()
(iii) Print T], T2, T 3 in HH:MM:SS format
(iv) T3 = T]. add'I'imefI's)
(v) T3. increment(50)
Test your code. (10 Marks)

20f3
18EC646

Module-5
9 a. Illustrate the following with the help of python construct:
(i) How to retrieve an image over HTTP? > *'
(ii) How to retrieve web pages with URLLib? (10 Marks)

b. Write a python program that retrieves a user's twitter friend, parse the returned JSON and
extract some information about the friend. (10 Marks)

OR
10 a. List the difference between XML and JSON? Write a simplej-python program to parse
JSON." (10 Marks)

b. Write a python program to create a table EmpDB with two departments (Quality control and
Testing). The fields of employee table are (EmpID, DeptName, GrossSalary). Establish a
database connection to EmpDB. Perform the following operations:
(i) Display employee details
(ii) Display Gross salary of employees working in the Quality control department
(iii) Display the total gross salary paid to the employee working in the quality control
department. (10 Marks)

*****

30f3

Common questions

Powered by AI

To count vowels, consonants, and blanks in a string, a Python program can iterate through each character of the input. Initialize counters for vowels, consonants, and blanks. For each character, perform the following checks: if it is a space, increment the blank counter; if it is a vowel (e.g., in 'aeiouAEIOU'), increment the vowel counter; if it is not a vowel and is alphabetic, increment the consonant counter. Utilizing methods like `isspace()` and `isalpha()`, the program can effectively categorize each character. For example: ``` vowels, consonants, blanks = 0, 0, 0 for char in string: if char.isspace(): blanks += 1 elif char.lower() in 'aeiou': vowels += 1 elif char.isalpha(): consonants += 1 ``` This approach ensures accurate categorization .

Fruitful functions in Python are those that return a value after execution, often used for computation tasks. For example, a function that calculates and returns the square of a number: `def square(x): return x * x`. Void functions, conversely, perform actions but do not return a value, primarily used for side effects like printing to the console or modifying global objects. For instance, `def print_square(x): print(x * x)` is a void because it only prints the result. The key distinction is in the presence of the `return` statement which provides flexibility in building more complex expressions in Python .

In Python, 'try' and 'except' are used to manage exceptions by isolating potentially error-throwing code within a 'try' block, and handling exceptions in the 'except' block. The basic syntax involves the 'try' keyword followed by a block of the code to test, an 'except' keyword, and a block of code for exception handling. For example: ``` try: # code that might cause an exception except ExceptionType as e: # code that runs if the exception occurs ``` This structure allows for specific error types to be caught and handled gracefully, ensuring the program can continue running or terminate in a controlled manner .

The 'continue' statement in Python is used inside loops to bypass the current iteration and jump to the next iteration, effectively skipping the rest of the code block for that loop cycle. It is particularly useful for efficiency in scenarios where certain conditions need no further processing within that iteration. For example, in a program summing only even numbers from a range: ``` total = 0 for num in range(1, 101): if num % 2 != 0: continue total += num ``` Here, the loop continues to the next iteration when an odd number is encountered (due to the 'continue' whenever `num % 2 != 0`), ensuring only even numbers contribute to the summation .

In Python, creating a class involves defining its structure using the `class` keyword, while objects are instances of these classes. The `__init__` method is a special method used as a constructor to initialize the object's attributes when an instance is created. It is called automatically upon object instantiation. For instance: ``` class Car: def __init__(self, make, model): self.make = make self.model = model my_car = Car('Toyota', 'Corolla') ``` Here, `Car` is the class, `my_car` is an object instance, and `self.make` and `self.model` get the values 'Toyota' and 'Corolla', respectively, from the parameters passed during object creation. The `__init__` method sets up initial states for the object properties .

Lists and tuples in Python both hold collections of items, but their mutability is a primary difference. Lists are mutable, allowing changes to their size or content, supporting operations such as appending, inserting, removing, or sorting elements (e.g., `list.append(x)`). Tuples, on the other hand, are immutable, meaning once created, their size and elements cannot change, providing a safeguard for fixed collections of items. This immutability makes tuples faster and more memory-efficient for fixed collections. Their usage depends on context: lists for dynamic, changeable data and tuples for static, constant data .

The 'pop()' method in Python is used to remove an item from a list at a specified position or, by default, the last item. It also returns the removed item. On the other hand, 'remove()' deletes the first occurrence of a value specified as its argument from the list but does not return the removed item. For instance, `list.pop(1)` will remove and return the element at index 1, while `list.remove('value')` will remove the first appearance of 'value'. Both methods mutate the original list .

XML and JSON are both data serialization formats with notable differences in syntax and usage. XML (Extensible Markup Language) uses a hierarchical structure with custom tags to represent data, which is verbose and flexible but can be complex to parse. JSON (JavaScript Object Notation) provides a lightweight format with key-value pairs, straightforward but less flexible in types and tags compared to XML. JSON is preferred for its simplicity and compatibility with JavaScript and many web APIs. In Python, a JSON object can be parsed using the `json` library: ``` import json json_data = '{"name": "John", "age": 30}' data = json.loads(json_data) ``` Here, `json.loads()` converts the JSON string into a Python dictionary. This ease of use and readability often make JSON favorable for web-related applications .

Python programs commonly encounter syntax errors, runtime errors, and semantic errors. Syntax errors occur when the code doesn't conform to the language's rules, causing immediate failure when executing, such as misspelling a keyword or using incorrect punctuation. Runtime errors happen during program execution due to issues like dividing by zero or file handling problems, usually resulting in exceptions. Semantic errors are flaws in program logic making it run but providing incorrect outcomes or behavior, such as incorrect formulas or condition checks. Identifying these involves debugging tools or careful code examination to isolate erroneous statements .

A valid password in the context of a Python program must include at least one lowercase letter, one digit, one uppercase letter, one special character from the set [$, @, #, !], and must be at least six characters long. This can be checked programmatically by iterating through each character of the password and using conditionals to track the fulfillment of each requirement. For instance, extracting characters to check their type (digit, alphabetic with lower or upper case) by using built-in methods like `isupper()`, `islower()`, and `isdigit()` can validate the programmatic conditions. Finally, checking the length ensures that minimum size constraints are met. If all conditions are true, the password is valid; otherwise, it is invalid .

You might also like