Header Ads Widget

Ticker

6/recent/ticker-posts

Programming In Python Practical

  LIST OF PRACTICALS

Sr.Practical TitleAnswer
1Introduction to various IDE for programming in python.Solution
2Data Types, Operators and conditional statements:
(a) Write a program to print “Hello World”.
(b) Write a program to find the maximum number out of 3 numbers.
(c) Write a program to swap the values of two variables without using temporary variable.
(d) Write a program to implement calculator.
(e) Write a Python program to calculate the sum of the digits in an integer.
Solution
3Control Structures and Functions:
a) Write a program for find factorial of a given number using iterative and recursive function.
b) Write a program which takes a sentence from user and calculates number of digits, letters, uppercase letters, lowercase letter and spaces in sentence.
c) Write a program to find GCD of two numbers.
d) Write a program to convert Decimal to hex, octal and binary
Solution
4Working with Data structure - Part I:
a) Write a program to remove duplicates from list.
b) Write a program to find frequency of elements of list.
c) Write a program to sort given list.
d) Write a program for matrix addition and matrix multiplication using list.
e) Write a program to generate Pascal’s triangle using list.
 f) Write a program to find minimum and maximum value in list of tuples.
g) Write a program to remove an element from tuple. 
Solution
5Working with Data structure - Part II:
a) Write a program to map 2 lists into a dictionary.
b) Write a program to invert keys and values of dictionary.
c) Write a program to generate dictionary of frequency of alphabets of given string. d) Write a Python program to sum all the items in a dictionary.
e) Write a script to concatenate given dictionaries
f) Create a dictionary where keys are name of students and values are another dictionary containing semester, age and cpi of that student.
• Print all the names of students.
• Print only names of students
• Print the name of student having highest CPI
Solution
6Object-oriented programming:
a) Create a class account with necessary methods – showBalance, withdraw, deposit and transfer. Also, implement necessary getters and setters. Instantiate 2 objects of that class and show different method calls using them.
b) Declare a class Person having name as member. Derive two classes a. Businessman - having income and number of people involved in his business as members. b. Employee - having income as a member. c. Create objects of both the classes and compare the income and print the name of one having greater income.
c) Create a class clock having 3 init parameters – hours, minutes and seconds. Write
following methods:
a. setClock – to set the time
b. displayTime – to show current time
c. tick – increase the time by one second

d) Create a base class A with 2 children B and C. class D having 2 parents B and C. Create a method named “Call” in every class. Use super in a way that a single call to method of class D execute “Call” method of every class.
Solution
7Exception handling and assertions:
a) Write a program that opens a file and writes data to it. Handle exceptions that can be generated during the I/O operations. 
b) Write a program that prompts the user to enter a number. If the number is positive or zero print it, otherwise raise an exception. A message “Code execution completed” should be displayed in both the cases, at the end of the execution.
c) Write a program to implement an interactive calculator. User input is expected to be a formula that consist of a number, an operator (at least + and -), and another number, separated by white space (e.g. 1 + 1). Split user input using str.split(), and check whether the resulting list is valid: a. If the input does not consist of 3 elements, raise a FormulaError, which is a custom Exception. b. Try to convert the first and third input to a float (like so: float_value = float(str_value)). Catch any ValueError that occurs, and instead raise a FormulaError. c. If the second input is not '+' or '-', again raise a FormulaError If the input is valid, perform the calculation and print out the result. The user is then prompted to provide new input, and so on, until the user enters quit.
d) Handle possible exceptions in the practical 6_a.
e) Write a program to find reciprocal of the elements of list [12,0, ‟a‟,20,‟hi‟] withException handling.
f) Write a program that takes percentage discount on product as input and returns the discounted price of product. Make sure that discount money cannot be less than zero and greater than original price of product using assertion.
g) Write a program that calculates division of two vectors and returns the result vector using raise keyword and exception handling

Solution
8File management:
a) Write a program to read n integers from the keyboard and store them into a file total.txtfile, separate odd and even numbers and store them in odd.txt and even.txt file. Display the content of all three files.
b) Write a program to copy content of one JSON file into another JSON file
Solution
9Regular Expressions:
a) Write a Python program that matches a string that has an a followed by one or more b's.
b) Write a Python program to find sequences of lowercase letters joined with a underscore.
c) Write a Python program to find all five characters long word in a string.
d) Write a regular expression for checking if given email address is in correct form or not. Correct form is: usename @ domain prefix followed by top level domain.(Top level domains can be – com/edu/org. Username can contain +/./_/-)
e) Write a code that takes email id as input. Extract top level domain name and print as output.
f) A website requires the users to input username and password to register. Write a program to check the validity of password input by users. Following are the criteria for checking the password:
• At least 1 letter between [a-z]
• At least 1 number between [0-9]
• 1. At least 1 letter between [A-Z]
• At least 1 character from [$#@]
• Minimum length of transaction password: 6
g) Maximum length of transaction password: 12
Solution
10Database operations:
a) Write a Python program to create a table named student with id, name and spi data.
b) Insert data in student table.
c) Display the list of students having spi greater than 8.
d) Create a table Course with id, name, and student id. Display the details of students who are registered for a specific course.
Solution
11Develop programs to learn GUI programming using Tkinter. Solution


Post a Comment

0 Comments