BSc IT sem 3 Python Programming practical solutions download




List of Practicals


1)a. Create a program that asks the user to enter their name and their age. Print out a message addressed to them that tells them the year that they will turn 100 years old. b. Enter the number from the user and depending on whether the number is even or odd, print out an appropriate message to the user. c. Write a program to generate the Fibonacci series. d. Write a function that reverses the user defined value. e. Write a function to check the input value is Armstrong and also write the function for Palindrome.


f. Write a recursive function to print the factorial for a given number.

2. Write the program for the following: a. Write a function that takes a character (i.e. a string of length 1) and returns True if it is a vowel, False otherwise. b. Define a function that computes the length of a given list or string. c. Define a procedurehistogram() that takes a list of integers and prints a histogram to the screen. For example, histogram([4, 9, 7]) should print the following: **** ********* *******


3. Write the program for the following: a. A pangram is a sentence that contains all the letters of the English alphabet at least once, for example: The quick brown fox jumps over the lazy dog. Your task here is to write a function to check a sentence to see if it is a pangram or not. b. Take a list, say for example this one: a=[1,1,2,3,5,8,13,21,34,55,89] and write a program that prints out all the elements of the list that are less than 5.


4. Write the program for the following: a. Write a program that takes two lists and returns True if they have at least one common member. b. Write a Python program to print a specified list after removing the 0th, 2nd, 4th and 5th elements. c. Write a Python program to clone or copy a list


5. Write the program for the following: a. Write a Python script to sort (ascending and descending) a dictionary by value. b. Write a Python script to concatenate following dictionaries to create a new one. Sample Dictionary : dic1={1:10, 2:20} dic2={3:30, 4:40} dic3={5:50,6:60} Expected Result : {1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60} c. Write a Python program to sum all the items in a dictionary.


6. Write the program for the following: a. Write a Python program to read an entire text file. b. Write a Python program to append text to a file and display the text. c. Write a Python program to read last n lines of a file.


7. Write the program for the following: a. Design a class that store the information of student and display the same b. Implement the concept of inheritance using python c. Create a class called Numbers, which has a single class attribute called MULTIPLIER, and a constructor which takes the parameters x and y (these should all be numbers). i. Write a method called add which returns the sum of the attributes x and y. ii. Write a class method called multiply, which takes a single number parameter a and returns the product of a and MULTIPLIER. iii. Write a static method called subtract, which takes two number parameters, b and c, and returns b - c. iv. Write a method called value which returns a tuple containing the values of x and y. Make this method into a property, and write a setter and a deleter for manipulating the values of x and y.


8. Write the program for the following: a. Open a new file in IDLE (“New Window” in the “File” menu) and save it as geometry.py in the directory where you keep the files you create for this course. Then copy the functions you wrote for calculating volumes and areas in the “Control Flow and Functions” exercise into this file and save it. Now open a new file and save it in the same directory. You should now be able to importyour own module like this: importgeometry Try and add print dir(geometry) to the file and run it. Now write a function pointyShapeVolume(x, y, squareBase) that calculates the volume of a square pyramid if squareBase is True and of a right circular cone if squareBase is False. x is the length of an edge on a square if squareBase is True and the radius of a circle when squareBase is False. y is the height of the object. First use squareBase to distinguish the cases. Use the circleArea and squareArea from the geometry module to calculate the base areas. b. Write a program to implement exception handling.


9. Write the program for the following: a. Try to configure the widget with various options like: bg=”red”, family=”times”, size=18 b. Try to change the widget type and configuration options to experiment with other widget types like Message, Button, Entry, Checkbutton, Radiobutton, Scale etc.


10. Design the database applications for the following: a. Design a simple database application that stores the records and retrieve the same. b. Design a database application to search the specified record from the database. c. Design a database application to that allows the user to add, delete and modify the records.